Ext.Loader.setPath('Ext.app', CONTEXT.contextPath+'/assets/ext4.2/plugins/portal/classes');
Ext.require([
    'Ext.layout.container.*',
    'Ext.resizer.Splitter',
    'Ext.fx.target.Element',
    'Ext.fx.target.Component',
    'Ext.window.Window',
    'Ext.app.Portlet',
    'Ext.app.PortalColumn',
    'Ext.app.PortalPanel',
    'Ext.app.PortalDropZone',
    'Ext.app.GridPortlet',
    'Ext.app.ChartPortlet'
]);
Ext.define('Ext.com.bkfm.Portal', {
    extend: 'Ext.panel.Panel',
    requires: ['Ext.app.PortalPanel', 'Ext.app.PortalColumn', 'Ext.app.GridPortlet', 'Ext.app.ChartPortlet'],
    initComponent: function(){
    	this.callParent(arguments);
    }
});
Ext.onReady(function(){
	Designer.initPage();
});
var Designer = {
		/**
		 * 流程设计器常量值
		 */
		CONSTANTS: {
			/**
			 * 流程节点类型
			 */
			CELL_TYPES:{
				START: 'start',
				START_NAME: '开始',
				END: 'end',
				END_NAME: '结束',
				JOINTLY: 'jointly',
				JOINTLY_NAME: '会签',
				TASK: 'task',
				TASK_NAME: '任务',
				LINE: 'line',
				LINE_NAME: '连接线'
			}
		},
		/**
		 * 流程设计器，设计面板
		 */
		graph: null,
		/**
		 * 节点类型,公共变量，记录整个流程图设计过程中创建节点的类型
		 */
		cell_Type: null,

		/**
		 * 工作流对象
		 */
		bkfmWorkFlowConfig: null,
		/**
		 * 获取工作流对象
		 */
		getBkfmWorkFlowConfig: function(){
			return this.bkfmWorkFlowConfig;
		},
		/**
		 * 流程业务表列表
		 */
		bkfmWorkFlowTables: null,
		/**
		 * 获取流程业务表列表
		 */
		getBkfmWorkFlowTables: function(){
			return this.bkfmWorkFlowTables;
		},
		/**
		 * 表单列表
		 */
		bkfmWorkFlowForms: null,
		/**
		 * 获取表单列表
		 */
		getBkfmWorkFlowForms: function(){
			return this.bkfmWorkFlowForms;
		},
		/**
		 * 初始化工作流程信息
		 */
		initWorkFlow: function(){
			var config = new BkfmWorkFlowConfig();
			config.setWorkFlowCode(Utils.getReqParams("WORKFLOW_CODE"));
			config.setWorkFlowName(Utils.getReqParams("WORKFLOW_NAME"));
			this.bkfmWorkFlowConfig = config;
			
			//初始化流程业务表
			var bkfmWorkFlowTables = new BkfmWorkFlowTables();
			this.bkfmWorkFlowTables = bkfmWorkFlowTables;
			
			//初始化表单列表
			var bkfmWorkFlowForms = new BkfmWorkFlowForms();
			this.bkfmWorkFlowForms = bkfmWorkFlowForms;
			
    		AjaxUtils.CallService({
				url: CONTEXT.contextPath+"/wf/v1/queryworkflow",
				params: {
					"workflow_code": Utils.getReqParams("WORKFLOW_CODE")
				},
				call: function(data){
					if(data.status == "OK"){
						var workflow_config = data.entity;
						//加载流程对象
						Designer.initWorkFlowConfig(workflow_config);
					}else{
						AjaxUtils.showError('获取流程信息异常');
					}
				}
			});
			
		},
		/**
		 * 初始化流程配置信息
		 * @param workFlowEntity 查询出流程配置信息
		 */
		initWorkFlowConfig: function(workFlowEntity){
			if(workFlowEntity ==null){
				return;
			}
			this.getBkfmWorkFlowConfig().setRwid(workFlowEntity.rwid);
			this.getBkfmWorkFlowConfig().setWorkFlowCode(workFlowEntity.workflow_code);
			this.getBkfmWorkFlowConfig().setWorkFlowName(workFlowEntity.workflow_name);
			this.getBkfmWorkFlowConfig().setWorkFlowStatus(workFlowEntity.workflow_status);
			
			if(!Ext.isEmpty(workFlowEntity.workflow_config)){
				var workFlowJson = Ext.JSON.decode(Utils.decrypt(workFlowEntity.workflow_config));
				this.getBkfmWorkFlowConfig().setWorkFlowXmlConfig(workFlowJson["workflow_xml_config"]);
				
				//初始化节点信息
				var workflow_nodes = workFlowJson["workflow_nodes"];
				Ext.Array.each(workflow_nodes,function(item,index){
					//添加单个节点
					var bkfmWorkFlowNode = new BkfmWorkFlowNode();
					bkfmWorkFlowNode.setRwid(item["rwid"]);
					bkfmWorkFlowNode.setNodeCode(item["node_code"]);
					bkfmWorkFlowNode.setNodeName(item["node_name"]);
					bkfmWorkFlowNode.setWorkFlowCode(item["workflow_code"]);
					bkfmWorkFlowNode.setNodePoints(item["node_points"]);
					bkfmWorkFlowNode.setNodeType(item["node_type"]);
					bkfmWorkFlowNode.setNodeFormName(item["node_form_name"]);
					bkfmWorkFlowNode.setApprovalPermis(item["approval_permis"]);
					bkfmWorkFlowNode.setBeforeActionHandler(item["beforeactionhandler"]);
					bkfmWorkFlowNode.setAfterActionHandler(item["afteractionhandler"]);
					
					//添加节点对应的用户权限
					var permis_users = (workflow_nodes[index])["permis_users"];
					Ext.Array.each(permis_users,function(userItem,userIndex){
						var bkfmWorkFlowNodePermisUser = new BkfmWorkFlowNodePermisUser();
						bkfmWorkFlowNodePermisUser.setRwid(userItem["rwid"]);
						bkfmWorkFlowNodePermisUser.setUserNo(userItem["user_no"]);
						bkfmWorkFlowNodePermisUser.setUserName(userItem["user_name"]);
						bkfmWorkFlowNodePermisUser.setNodeCode(userItem["node_code"]);
						bkfmWorkFlowNodePermisUser.setNodeName(userItem["node_name"]);
						bkfmWorkFlowNodePermisUser.setWorkFlowCode(userItem["workflow_code"]);
						bkfmWorkFlowNodePermisUser.setWorkFlowName(userItem["workflow_name"]);
						bkfmWorkFlowNode.getPermisUsers().addBkfmWorkFlowNodePermisUser(bkfmWorkFlowNodePermisUser);
					});
					
					//添加节点对应角色权限
					var permis_roles = (workflow_nodes[index])["permis_roles"];
					Ext.Array.each(permis_roles,function(roleItem,roleIndex){
						var bkfmWorkFlowNodePermisRole = new BkfmWorkFlowNodePermisRole();
						bkfmWorkFlowNodePermisRole.setRwid(roleItem["rwid"]);
						bkfmWorkFlowNodePermisRole.setRoleId(roleItem["role_id"]);
						bkfmWorkFlowNodePermisRole.setRoleName(roleItem["role_name"]);
						bkfmWorkFlowNodePermisRole.setNodeCode(roleItem["node_code"]);
						bkfmWorkFlowNodePermisRole.setNodeName(roleItem["node_name"]);
						bkfmWorkFlowNodePermisRole.setWorkFlowCode(roleItem["workflow_code"]);
						bkfmWorkFlowNodePermisRole.setWorkFlowName(roleItem["workflow_name"]);
						
						bkfmWorkFlowNode.getPermisRoles().addBkfmWorkFlowNodePermisRole(bkfmWorkFlowNodePermisRole);
					});
					
					//添加节点对应部门权限
					var permis_depts = (workflow_nodes[index])["permis_depts"];
					Ext.Array.each(permis_depts,function(deptItem,deptIndex){
						var bkfmWorkFlowNodePermisDept = new BkfmWorkFlowNodePermisDept();
						bkfmWorkFlowNodePermisDept.setRwid(deptItem["rwid"]);
						bkfmWorkFlowNodePermisDept.setOrgId(deptItem["org_id"]);
						bkfmWorkFlowNodePermisDept.setOrgName(deptItem["org_name"]);
						bkfmWorkFlowNodePermisDept.setNodeCode(deptItem["node_code"]);
						bkfmWorkFlowNodePermisDept.setNodeName(deptItem["node_name"]);
						bkfmWorkFlowNodePermisDept.setWorkFlowCode(deptItem["workflow_code"]);
						bkfmWorkFlowNodePermisDept.setWorkFlowName(deptItem["workflow_name"]);
						bkfmWorkFlowNode.getPermisDepts().addBkfmWorkFlowNodePermisDept(bkfmWorkFlowNodePermisDept);
					});
					
					//添加节点
					Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().addBkfmWorkFlowNode(bkfmWorkFlowNode);
				});
				
				//初始化连接线
				Ext.Array.each(workFlowJson["workflow_lines"],function(item,index){
					var  bkfmWorkFlowLine = new BkfmWorkFlowLine();
					bkfmWorkFlowLine.setRwid(item["rwid"]);
					bkfmWorkFlowLine.setSourceNodeCode(item["sourcenode_code"]);
					bkfmWorkFlowLine.setSourceNodeName(item["sourcenode_name"]);
					bkfmWorkFlowLine.setConditions(item["conditions"]);
					bkfmWorkFlowLine.setActionCode(item["action_code"]);
					bkfmWorkFlowLine.setActionName(item["action_name"]);
					bkfmWorkFlowLine.setTargetNodeCode(item["targetnode_code"]);
					bkfmWorkFlowLine.setTargetNodeName(item["targetnode_name"]);
					
					Designer.getBkfmWorkFlowConfig().getWorkFlowLines().addBkfmWorkFlowLine(bkfmWorkFlowLine);
				});
				
				//初始化表
				Ext.Array.each(workFlowJson["workflow_tables"],function(item,index){
					var workFlowTable = new BkfmWorkFlowTable();
					workFlowTable.setRwid(item["rwid"]);
					workFlowTable.setWorkFlowCode(item["workflow_code"]);
					workFlowTable.setWorkFlowName(item["workflow_name"]);
					workFlowTable.setTablePath(item["table_path"]);
					workFlowTable.setTableName(item["table_name"]);
					workFlowTable.setTableType(item["table_type"]);
					workFlowTable.setTableTypeName(item["table_type_name"]);
					Designer.getBkfmWorkFlowTables().addWorkFlowTable(workFlowTable);
				});
				
				//初始化表单
				var workflow_forms = workFlowJson["workflow_forms"];
				Ext.Array.each(workflow_forms,function(item,index){
					var bkfmWorkFlowForm = new BkfmWorkFlowForm();
					bkfmWorkFlowForm.setRwid(item["rwid"]);
					bkfmWorkFlowForm.setWorkFlowCode(item["workflow_code"]);
					bkfmWorkFlowForm.setWorkFlowName(item["workflow_name"]);
					bkfmWorkFlowForm.setWorkFlowFormName(item["workflow_form_name"]);
					
					//表单页面配置项
					var workflow_form_pageitems = (workflow_forms[index])["workflow_form_pageitems"];
					Ext.Array.each(workflow_form_pageitems,function(pageItem,pageItemIndex){
						var bkfmWorkFlowFormPageItem = new BkfmWorkFlowFormPageItem();
						bkfmWorkFlowFormPageItem.setRwid(pageItem["rwid"]);
						bkfmWorkFlowFormPageItem.setWorkFlowFormName(pageItem["workflow_form_name"]);
						bkfmWorkFlowFormPageItem.setPageItemType(pageItem["pageitem_type"]);
						bkfmWorkFlowFormPageItem.setPageTypeName(pageItem["pageitem_type_name"]);
						bkfmWorkFlowFormPageItem.setPageTitle(pageItem["pageitem_title"]);
						bkfmWorkFlowFormPageItem.setTablePath(pageItem["table_path"]);
						bkfmWorkFlowFormPageItem.setTableName(pageItem["table_name"]);
						debugger;
						bkfmWorkFlowFormPageItem.setOrderBy(pageItem["order_by"]);
						bkfmWorkFlowFormPageItem.setPageItemFormColumnCount(pageItem["pageitem_form_columncount"]);
						bkfmWorkFlowFormPageItem.setPageItemHeight(pageItem["pageitem_height"]);
						bkfmWorkFlowFormPageItem.setIsSave(pageItem["is_save"]);
						bkfmWorkFlowFormPageItem.setIsAdd(pageItem["is_add"]);
						bkfmWorkFlowFormPageItem.setIsEdit(pageItem["is_edit"]);
						bkfmWorkFlowFormPageItem.setIsDelete(pageItem["is_delete"]);
						
						//只读字段
						var readonlyfields = (workflow_form_pageitems[pageItemIndex])["readonlyfields"];
						Ext.Array.each(readonlyfields,function(readonlyItem,readonlyItemIndex){
							var bkfmWorkFlowFormPageItemReadOnlyField = new BkfmWorkFlowFormPageItemReadOnlyField();
							bkfmWorkFlowFormPageItemReadOnlyField.setRwid(readonlyItem["rwid"]);
							bkfmWorkFlowFormPageItemReadOnlyField.setFieldId(readonlyItem["field_id"]);
							bkfmWorkFlowFormPageItemReadOnlyField.setFieldName(readonlyItem["field_name"]);
							
							bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemReadOnlyFields().addBkfmWorkFlowFormPageItemReadOnlyField(bkfmWorkFlowFormPageItemReadOnlyField);
						});
						
						//隐藏字段
						var hiddenfields = (workflow_form_pageitems[pageItemIndex])["hiddenfields"];
						Ext.Array.each(hiddenfields,function(hiddenItem,hiddenItemIndex){
							var bkfmWorkFlowFormPageItemHiddenField = new BkfmWorkFlowFormPageItemHiddenField();
							bkfmWorkFlowFormPageItemHiddenField.setRwid(hiddenItem["rwid"]);
							bkfmWorkFlowFormPageItemHiddenField.setFieldId(hiddenItem["field_id"]);
							bkfmWorkFlowFormPageItemHiddenField.setFieldName(hiddenItem["field_name"]);
							
							bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemHiddenFields().addBkfmWorkFlowFormPageItemHiddenField(bkfmWorkFlowFormPageItemHiddenField);
						});
						
						bkfmWorkFlowForm.getWorkFlowFormPageItems().addBkfmWorkFlowFormPageItem(bkfmWorkFlowFormPageItem);
					});
					Designer.getBkfmWorkFlowForms().addBkfmWorkFlowForm(bkfmWorkFlowForm);
				});
			}
			
			//
			
			//生成流程图
			this.showWorkFlowChart();
		},
		/**
		 * 根据流程xml文件显示流程图到设计器面板
		 */
		showWorkFlowChart: function(){
			var workFlowXml = this.getBkfmWorkFlowConfig().getWorkFlowXmlConfig();
			var node = mxUtils.parseXml(workFlowXml);
			decoder = new mxCodec();
			decoder.decode(node.documentElement, this.graph.getModel());
			this.graph.getModel().endUpdate();
		},
		/**
		 * 页面初始化
		 */
		initPage: function(){
			Ext.create('Ext.container.Viewport', {
			    layout: 'border',
			    frame:false,
			    border:false,
			    items: [{
			    	title: '元素属性',
			    	id: 'leftPanel',
			    	region: 'east',
			    	width: 220,
			    	border: false,
			    	items:[{
			    		xtype: 'fieldset',
			    		title: '流程属性',
			    		height: Utils.getHeight()*0.3,
			    		items:[{
			    			xtype: 'form',
			    			id: 'flowInfoForm',
			    			border: false,
			    			items:[{
			    				xtype: 'numberfield',
			    				id: 'workflow_code',
			    				fieldLabel: '编码',
			    				labelWidth: 30,
			    				readOnly: true,
			    				value: Utils.getReqParams("WORKFLOW_CODE")//Designer.getBkfmWorkFlowConfig().getWorkFlowCode()
			    			},{
			    				xtype: 'textfield',
			    				id: 'workflow_name',
			    				fieldLabel: '名称',
			    				labelWidth: 30,
			    				readOnly: true,
			    				value: Utils.getReqParams("WORKFLOW_NAME")//Designer.bkfmWorkFlowConfig.getWorkFlowName()
			    			}]
			    		}]
			    	},{
			    		xtype: 'fieldset',
			    		title: '元素属性',
			    		height: Utils.getHeight()*0.35,
			    		items:[{
			    			xtype: 'form',
			    			id: 'cellInfoForm',
			    			border: false,
			    			items:[{
			    				xtype: 'textfield',
			    				id: 'cellNo',
			    				fieldLabel: '编码',
			    				labelWidth:30,
			    				disabled: true
			    			},{
			    				xtype: 'combo',
			    				id: 'cellType',
			    				fieldLabel: '节点类型',
			    				labelWidth:30,
			    				disabled: true,
			    				queryMode: 'local',
			    				displayField: 'DISPLAYVALUE',
			    			    valueField: 'VALUE',
			    			    store:Ext.create('Ext.data.Store', {
			    			        fields: ['VALUE', 'DISPLAYVALUE'],
			    			        data : [
			    			            {"VALUE": Designer.CONSTANTS.CELL_TYPES.START, "DISPLAYVALUE": Designer.CONSTANTS.CELL_TYPES.START_NAME},
			    			            {"VALUE": Designer.CONSTANTS.CELL_TYPES.TASK, "DISPLAYVALUE": Designer.CONSTANTS.CELL_TYPES.TASK_NAME},
			    			            {"VALUE": Designer.CONSTANTS.CELL_TYPES.JOINTLY, "DISPLAYVALUE": Designer.CONSTANTS.CELL_TYPES.JOINTLY_NAME},
			    			            {"VALUE": Designer.CONSTANTS.CELL_TYPES.END,"DISPLAYVALUE": Designer.CONSTANTS.CELL_TYPES.END_NAME},
			    			            {"VALUE": Designer.CONSTANTS.CELL_TYPES.LINE,"DISPLAYVALUE": Designer.CONSTANTS.CELL_TYPES.LINE_NAME}
			    			        ]
			    			    })
			    			},{
			    				xtype: 'textfield',
			    				id: 'cellText',
			    				fieldLabel: '名称',
			    				labelWidth: 30
			    			},{
			    				xtype: 'textfield',
			    				id: 'points',
			    				fieldLabel: '坐标',
			    				labelWidth: 30,
			    				readOnly: true
			    			}]
			    		}]
			    	},{
			    		xtype: 'fieldset',
			    		title: '流程缩略图',
			    		height: Utils.getHeight()*0.23,
			    		style: 'padding:0px;',
			    		html: '<div id="outlineContainer" style="z-index:1;overflow:hidden;top:0px;right:0px;width:100%;height:100%;background:transparent;border-style:solid;border-color:lightgray;"></div>'
			    	}]
			    },{
			    	id: 'mainPanel',
			        region: 'center',
			        layout: 'fit',
			        items:[{
			        	xtype: 'panel',
			        	id: 'canvas',
			        	border: false,
			        	autoScroll: true,
			        	html: '<div id="graphContainer" style="width:100%;height:100%;background-image:url(\''+CONTEXT.contextPath+'/assets/wf/examples/editors/images/grid.gif\')"></div>'
			        }],
			        tbar:[{
			        	iconCls:'startNode',
			        	id: 'startNode',
			        	cellType: Designer.CONSTANTS.CELL_TYPES.START,
			        	tooltip: Designer.CONSTANTS.CELL_TYPES.START_NAME,
			        	tooltipType:'title',
			        	toggleGroup: 'brand',
			        	enableToggle:true,
			        	handler: function(self){
			        		Designer.pressBtn = self.id;
			        		Designer.cell_Type = self.cellType;
			        	}
			        },{
			        	iconCls: 'taskNode',
			        	id: 'taskNode',
			        	cellType: Designer.CONSTANTS.CELL_TYPES.TASK,
			        	tooltip: Designer.CONSTANTS.CELL_TYPES.TASK_NAME,
			        	tooltipType:'title',
			        	toggleGroup: 'brand',
			        	enableToggle:true,
			        	handler: function(self){
			        		Designer.pressBtn = self.id;
			        		Designer.cell_Type = self.cellType;
			        	}
			        },{
			        	iconCls: 'jointly_sign',
			        	id: 'jointlySignNode',
			        	cellType: Designer.CONSTANTS.CELL_TYPES.JOINTLY,
			        	tooltip: Designer.CONSTANTS.CELL_TYPES.JOINTLY_NAME,
			        	tooltipType:'title',
			        	toggleGroup: 'brand',
			        	enableToggle:true,
			        	handler: function(self){
			        		Designer.pressBtn = self.id;
			        		Designer.cell_Type = self.cellType;
			        	}
			        },{
			        	iconCls: 'endNode',
			        	id: 'endNode',
			        	cellType: Designer.CONSTANTS.CELL_TYPES.END,
			        	tooltip: Designer.CONSTANTS.CELL_TYPES.END_NAME,
			        	tooltipType:'title',
			        	toggleGroup: 'brand',
			        	enableToggle:true,
			        	handler: function(self){
			        		Designer.pressBtn = self.id;
			        		Designer.cell_Type = self.cellType;
			        	}
			        },'-',{
			        	iconCls: 'zoom_in',
			        	tooltip: '放大',
			        	tooltipType:'title',
			        	handler: function(){
			        		Designer.graph.zoomIn();
			        	}
			        },{
			        	iconCls: 'zoom_out',
			        	tooltip: '缩小',
			        	tooltipType:'title',
			        	handler: function(){
			        		Designer.graph.zoomOut();
			        	}
			        },{
			        	iconCls: 'zoom',
			        	tooltip: '还原',
			        	tooltipType:'title',
			        	handler: function(){
			        		Designer.graph.zoomActual();
			        	}
			        },'-',{
			        	iconCls: 'edit',
			        	tooltip: '编辑',
			        	tooltipType:'title'
			        },{
			        	iconCls: 'delete',
			        	tooltip: '删除',
			        	tooltipType:'title',
			        	handler: function(){
			        		Designer.deleteNode(Designer.graph.getSelectionCell());
			        	}
			        },'->',{
			        	text: '保存',
			        	iconCls: 'save',
			        	handler: function(){
			        		Designer.saveWorkFlow();
			        	}
			        },{
			        	text: '关闭',
			        	iconCls: 'close',
			        	handler: function(){
			        		AjaxUtils.showConfirm(function(){
			        			window.parent.FlowManager.closeFlowDesinger();
							},"确定需要关闭流程设计器，请确保当前流程已经保存?");
			        		
			        	}
			        }]
			    }],
			    listeners:{
			    	render: function(){
			    		//初始化流程图设计器界面
						var container = document.getElementById("graphContainer");
						Designer.createFlowCanvas(container);
						//初始化流程对象
						Designer.initWorkFlow();
					}
				}
			});
		},
		/**
		 * 校验流程合法性
		 * true/false
		 */
		checkFlow: function(){
			var bool = true;
			//校验是否存在开始节点
			if(!this.checkStartNode()){
				AjaxUtils.showError("流程没有创建开始节点");
				bool= false;
			}
			//校验是否存在结束节点
			if(!this.checkEndNode()){
				AjaxUtils.showError("流程没有创建结束节点");
				bool= false;
			}
			//校验节点是否已经全部连接
			Ext.Array.each(this.graph.getChildCells(),function(cellNode, index, countriesItSelf){
				
				var node_code = cellNode.getId();
				var line_action_code = cellNode.getId();
				if(cellNode.cellType=="start"){
					var selectWorkFlowNode = Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().getBkfmWorkFlowNode(node_code);
					//判断是否存在了开始
					var lines = Designer.getBkfmWorkFlowConfig().getWorkFlowLines().getBkfmWorkFlowNodeStartLines(selectWorkFlowNode);
					if(lines.getBkfmWorkFlowLines().length ==0){
						AjaxUtils.showError('流程节点“'+cellNode.value+'”，没有配置连接线');
						bool= false;
						return false;
					}
				}else if(cellNode.cellType=="end"){
					//判断是否存在了开始
					var selectWorkFlowNode = Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().getBkfmWorkFlowNode(node_code);
					var lines = Designer.getBkfmWorkFlowConfig().getWorkFlowLines().getBkfmWorkFlowNodeEndLines(selectWorkFlowNode);
					if(lines.getBkfmWorkFlowLines().length ==0){
						AjaxUtils.showError('流程节点“'+cellNode.value+'”，没有配置连接线');
						bool= false;
						return false;
					}
					var startlines = Designer.getBkfmWorkFlowConfig().getWorkFlowLines().getBkfmWorkFlowNodeStartLines(selectWorkFlowNode);
					if(startlines.getBkfmWorkFlowLines().length>0){
						AjaxUtils.showError('结束节点存在不合法的流程连接线');
						bool= false;
						return false;
					}
				}else if(cellNode.cellType=="line"){
					var line =  Designer.getBkfmWorkFlowConfig().getWorkFlowLines().getBkfmWorkFlowLine(line_action_code);
					if(line.getSourceNodeCode()==null || line.getTargetNodeCode()==null){
						AjaxUtils.showError('存在无效的连接线');
						bool = false;
						return false;
					}
				}else if(!cellNode.cellType){
					AjaxUtils.showError('无效的设计流程，请确认流程是否配置完整');
					bool = false;
					return false;
				}else{
					var selectWorkFlowNode = Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().getBkfmWorkFlowNode(node_code);
					var startlines = Designer.getBkfmWorkFlowConfig().getWorkFlowLines().getBkfmWorkFlowNodeStartLines(selectWorkFlowNode);
					var endlines = Designer.getBkfmWorkFlowConfig().getWorkFlowLines().getBkfmWorkFlowNodeEndLines(selectWorkFlowNode);
					if(startlines.getBkfmWorkFlowLines().length ==0 || endlines.getBkfmWorkFlowLines().length == 0){
						AjaxUtils.showError('流程节点“'+cellNode.value+'”，没有配置连接线');
						bool= false;
						return false;
					}
				}
			});
			//判断所有连接线是否都存在开始和结束节点
			return bool;
		},
		/**
		 * 保存流程图
		 */
		saveWorkFlow: function(){
    		if(!Designer.checkFlow()){
    			return;
    		}
    		//获取流程图
    		var enc = new mxCodec();
    		alert(enc.encode(Designer.graph.getModel()).outerHTML);
    		var workFlowConfigJson = this.parseWorkFlowConfig(enc.encode(Designer.graph.getModel()).outerHTML);
    		workFlowConfigJson["workflow_config"] = JSON.stringify(workFlowConfigJson);
    		AjaxUtils.CallService({
				url: CONTEXT.contextPath+"/wf/v1/save",
				dataType: "json",
				//params: Utils.encrypt(JSON.stringify(workFlowConfigJson)),
				params: workFlowConfigJson,
				call: function(data){
					if(data.status == "OK"){
						AjaxUtils.showInfo('保存成功');

					}else{
						AjaxUtils.showError('保存流程失败');
					}
				}
			});
		},
		/**
		 * 解析工作流设计器配置内容,返回配置的json对象
		 */
		parseWorkFlowConfig: function(workFlowXml){
			var workFlowConfig = this.getBkfmWorkFlowConfig();
			var workFlowConfigJson = {
					"rwid": workFlowConfig.getRwid(),
					"workflow_code": workFlowConfig.getWorkFlowCode(),
					"workflow_name": workFlowConfig.getWorkFlowName(),
					"workflow_xml_config": workFlowXml,
					"workflow_status": workFlowConfig.getWorkFlowStatus(),
					"workflow_nodes": [],
					"workflow_lines": [],
					"workflow_tables": [],
					"workflow_forms": []
			};
			//遍历获取流程节点
			Ext.Array.each(workFlowConfig.getWorkFlowNodes().getBkfmWorkFlowNodes(),function(bkfmWorkFlowNode,index){
				workFlowConfigJson["workflow_nodes"].push({
					"rwid": bkfmWorkFlowNode.getRwid(),
					"node_code": bkfmWorkFlowNode.getNodeCode(),
					"node_name": bkfmWorkFlowNode.getNodeName(),
					"workflow_code": bkfmWorkFlowNode.getWorkFlowCode(),
					"node_points": bkfmWorkFlowNode.getNodePoints(),
					"node_type": bkfmWorkFlowNode.getNodeType(),
					"node_form_name": bkfmWorkFlowNode.getNodeFormName(),
					"approval_permis": bkfmWorkFlowNode.getApprovalPermis(),
					"beforeactionhandler": bkfmWorkFlowNode.getBeforeActionHandler(),
					"afteractionhandler": bkfmWorkFlowNode.getAfterActionHandler(),
					"permis_users": [],
					"permis_roles": [],
					"permis_depts": []
				});
				//遍历节点的人员权限
				Ext.Array.each(bkfmWorkFlowNode.getPermisUsers().getBkfmWorkFlowNodePermisUsers(),function(bkfmWorkFlowNodePermisUser,permisUserIndex){
					var workFlowNodes = workFlowConfigJson["workflow_nodes"][index];
					workFlowNodes["permis_users"].push({
						"rwid": bkfmWorkFlowNodePermisUser.getRwid(),
						"user_no": bkfmWorkFlowNodePermisUser.getUserNo(),
						"user_name": bkfmWorkFlowNodePermisUser.getUserName(),
						"node_code": bkfmWorkFlowNodePermisUser.getNodeCode(),
						"node_name": bkfmWorkFlowNodePermisUser.getNodeName(),
						"workflow_code": bkfmWorkFlowNodePermisUser.getWorkFlowCode(),
						"workflow_name": bkfmWorkFlowNodePermisUser.getWorkFlowName()
					});
				});
				//编辑节点的角色权限
				Ext.Array.each(bkfmWorkFlowNode.getPermisRoles().getBkfmWorkFlowNodePermisRoles(),function(bkfmWorkFlowNodePermisRole,permisRoleIndex){
					var workFlowNodes = workFlowConfigJson["workflow_nodes"][index];
					workFlowNodes["permis_roles"].push({
						"rwid": bkfmWorkFlowNodePermisRole.getRwid(),
						"role_id": bkfmWorkFlowNodePermisRole.getRoleId(),
						"role_name": bkfmWorkFlowNodePermisRole.getRoleName(),
						"node_code": bkfmWorkFlowNodePermisRole.getNodeCode(),
						"node_name": bkfmWorkFlowNodePermisRole.getNodeName(),
						"workflow_code": bkfmWorkFlowNodePermisRole.getWorkFlowCode(),
						"workflow_name": bkfmWorkFlowNodePermisRole.getWorkFlowName()
					});
				});
				//遍历节点的部门权限
				Ext.Array.each(bkfmWorkFlowNode.getPermisDepts().getBkfmWorkFlowNodePermisDepts(),function(bkfmWorkFlowNodePermisDept,permisDeptIndex){
					var workFlowNodes = workFlowConfigJson["workflow_nodes"][index];
					workFlowNodes["permis_depts"].push({
						"rwid": bkfmWorkFlowNodePermisDept.getRwid(),
						"org_id": bkfmWorkFlowNodePermisDept.getOrgId(),
						"org_name": bkfmWorkFlowNodePermisDept.getOrgName(),
						"node_code": bkfmWorkFlowNodePermisDept.getNodeCode(),
						"node_name": bkfmWorkFlowNodePermisDept.getNodeName(),
						"workflow_code": bkfmWorkFlowNodePermisDept.getWorkFlowCode(),
						"workflow_name": bkfmWorkFlowNodePermisDept.getWorkFlowName()
					});
				});
			});
			//获取连接线
			Ext.Array.each(workFlowConfig.getWorkFlowLines().getBkfmWorkFlowLines(),function(bkfmWorkFlowLine,index){
				workFlowConfigJson["workflow_lines"].push({
					"rwid": bkfmWorkFlowLine.getRwid(),
					"sourcenode_code": bkfmWorkFlowLine.getSourceNodeCode(),
					"sourcenode_name": bkfmWorkFlowLine.getSourceNodeName(),
					"conditions": bkfmWorkFlowLine.getConditions(),
					"action_code": bkfmWorkFlowLine.getActionCode(),
					"action_name": bkfmWorkFlowLine.getActionName(),
					"targetnode_code": bkfmWorkFlowLine.getTargetNodeCode(),
					"targetnode_name": bkfmWorkFlowLine.getTagetNodeName() 
				});
			});
			
			//流程业务表单
			Ext.Array.each(Designer.getBkfmWorkFlowTables().getWorkFlowTables(),function(workFlowTable,index){
				workFlowConfigJson["workflow_tables"].push({
					"rwid": workFlowTable.getRwid(),
					"workflow_code": workFlowTable.getWorkFlowCode(),
					"workflow_name": workFlowTable.getWorkFlowName(),
					"table_path": workFlowTable.getTablePath(),
					"table_name": workFlowTable.getTableName(),
					"table_type": workFlowTable.getTableType(),
					"table_type_name": workFlowTable.getTableTypeName()
				});
			});
			
			//流程表单
			Ext.Array.each(Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForms(),function(bkfmWorkFlowForm,index){
				workFlowConfigJson["workflow_forms"].push({
					"rwid": bkfmWorkFlowForm.getRwid(),
					"workflow_code": bkfmWorkFlowForm.getWorkFlowCode(),
					"workflow_name": bkfmWorkFlowForm.getWorkFlowName(),
					"workflow_form_name": bkfmWorkFlowForm.getWorkFlowFormName(),
					"workflow_form_pageitems": [],
				});
				//表单页面配置项列表
				Ext.Array.each(bkfmWorkFlowForm.getWorkFlowFormPageItems().getBkfmWorkFlowFormPageItems(),function(bkfmWorkFlowFormPageItem,pageItemIndex){
					var workFlowForm = workFlowConfigJson["workflow_forms"][index];
					workFlowForm["workflow_form_pageitems"].push({
						"rwid": bkfmWorkFlowFormPageItem.getRwid(),
						"workflow_form_name": bkfmWorkFlowFormPageItem.getWorkFlowFormName(),
						"pageitem_type": bkfmWorkFlowFormPageItem.getPageItemType(),
						"pageitem_type_name": bkfmWorkFlowFormPageItem.getPageTypeName(),
						"pageitem_title": bkfmWorkFlowFormPageItem.getPageTitle(),
						"table_path": bkfmWorkFlowFormPageItem.getTablePath(),
						"table_name": bkfmWorkFlowFormPageItem.getTableName(),
						"order_by": bkfmWorkFlowFormPageItem.getOrderBy(),
						"pageitem_form_columncount": bkfmWorkFlowFormPageItem.getPageItemFormColumnCount(),
						"pageitem_height": bkfmWorkFlowFormPageItem.getPageItemHeight(),
						"is_save": bkfmWorkFlowFormPageItem.getIsSave(),
						"is_add": bkfmWorkFlowFormPageItem.getIsAdd(),
						"is_edit": bkfmWorkFlowFormPageItem.getIsEdit(),
						"is_delete": bkfmWorkFlowFormPageItem.getIsDelete(),
						"readonlyfields": [],
						"hiddenfields": []
					});
					//遍历表单页面配置项只读字段
					Ext.Array.each(bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemReadOnlyFields().getBkfmWorkFlowFormPageItemReadOnlyFields(),function(bkfmWorkFlowFormPageItemReadOnlyField,readOnlyFieldIndex){
						var workflow_form_pageitem = workFlowForm["workflow_form_pageitems"][pageItemIndex];
						workflow_form_pageitem["readonlyfields"].push({
							"rwid": bkfmWorkFlowFormPageItemReadOnlyField.getRwid(),
							"field_id": bkfmWorkFlowFormPageItemReadOnlyField.getFieldId(),
							"field_name": bkfmWorkFlowFormPageItemReadOnlyField.getFieldName()
						});
					});
					//遍历表单页面配置项隐藏字段
					Ext.Array.each(bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemHiddenFields().getBkfmWorkFlowFormPageItemHiddenFields(),function(bkfmWorkFlowFormPageItemHiddenField,readOnlyFieldIndex){
						var workflow_form_pageitem = workFlowForm["workflow_form_pageitems"][pageItemIndex];
						workflow_form_pageitem["hiddenfields"].push({
							"rwid": bkfmWorkFlowFormPageItemHiddenField.getRwid(),
							"field_id": bkfmWorkFlowFormPageItemHiddenField.getFieldId(),
							"field_name": bkfmWorkFlowFormPageItemHiddenField.getFieldName()
						});
					});
				})
			});
			
			return workFlowConfigJson;
		},
		/**
		 * 设置鼠标在设计器中的位置
		 */
		setPoint: function(x,y){
			this.x = x;
			this.y = y;
		},
		getX: function(){
			return this.x;
		},
		getY: function(){
			return this.y;
		},
		/**
		 * 创建工作流画布
		 * @param container 容器名称
		 */
		createFlowCanvas: function(container){
			//设置显示连接线的图标
			mxConnectionHandler.prototype.connectImage = new mxImage(CONTEXT.contextPath+"/assets/wf/src/images/icons/arrow.gif", 14, 14);
			if (!mxClient.isBrowserSupported()) {
				//如果浏览器不支持，显示错误信息。
				//mxUtils.error('Browser is not supported!', 200, false);
				AjaxUtils.showError("流程设计器不支持当前使用浏览器");
				return;
			}
			
			// 禁用浏览器自带右键菜单  
	        mxEvent.disableContextMenu(document.body);
	        //能够实现在SVG中清晰呈现矩形，即：去锯齿效果
			mxRectangleShape.prototype.crisp = true;
			//在给定的容器中创建的图形
			var graph = new mxGraph(container);
			this.graph = graph;
			//设置对象显示连接线
			graph.setPanning(true);
			graph.setTooltips(true);
			//是否允许Cells通过其中部的连接点新建连接,false则通过连接线连接
			graph.setConnectable(true);
			//设置元素不可以双击直接编辑
			graph.setCellsEditable(false);
			//是否允许重复连接
			graph.setMultigraph(false);
			// Label 将显示 Html 格式的 Value
			graph.setHtmlLabels(true);
			//设置连接线的连接方式为拐点方式
			var style = graph.getStylesheet().getDefaultEdgeStyle();
			//折角的地方为圆弧
			style[mxConstants.STYLE_ROUNDED] = true;
			style[mxConstants.STYLE_EDGE] = mxEdgeStyle.ElbowConnector;
			graph.alternateEdgeStyle = 'elbow=vertical';
			
			//创建设计器右击快捷菜单
			graph.popupMenuHandler.factoryMethod = function(menu, cell, evt)
			{
				//graph.clearSelection();
				//return createPopupMenu(graph, menu, cell, evt);
				return Designer.contextDesignerMenu(menu, cell, evt);
			};
			// 创建下拉菜单  
			new mxRubberband(graph);
			//获取布局
			var layout = new mxHierarchicalLayout(graph);
			// 在对象中创建默认组件
			var parent = graph.getDefaultParent();
			
			//点击事件
			graph.click = function (evt) {
				//获取选中或者生成的节点元素
				var sel_cell = null;
				if(Designer.cell_Type !=null){
					//画节点
					try{
						Designer.setPoint(evt.getX(),evt.getY());
						sel_cell = Designer.createNode();
					}finally{
						Designer.cell_Type = null;
						if(!Ext.isEmpty(Designer.pressBtn)){
							Ext.getCmp(Designer.pressBtn).toggle();
						}
						
					}
				}
				//获取选择节点
				if(sel_cell == null){
					sel_cell = Designer.graph.getSelectionCell();
				}
				//更新选择的cell任务节点
				Designer.updateWorkFlowNode(sel_cell);
				Designer.showNodeInfo(sel_cell);
			};
			//捕获连接线事件
			graph.addListener(mxEvent.CELL_CONNECTED, function(edge, terminal, source, constraint) {
				var source = terminal.getProperties().edge.source;
				var target = terminal.getProperties().edge.target;
				var lineId = terminal.getProperties().edge.id;
				var lineName = terminal.getProperties().edge.value||'';
				if(target !=null){
					
					terminal.getProperties().edge.cellType =  Designer.CONSTANTS.CELL_TYPES.LINE;
					//添加连接线
					Designer.addWorkFlowLine(lineId,lineName,source.getId(),source.value,target.getId(),target.value,"");
				}
			});
			//键盘事件
			var keyHandler = new mxKeyHandler(graph);
			//删除
			keyHandler.bindKey(46, function (keyEvent) {
				Designer.deleteNode(Designer.graph.getSelectionCell());
			});
			
			//显示流程图缩略图
			var outline = document.getElementById('outlineContainer');
			if (mxClient.IS_QUIRKS){
				new mxDivResizer(outline);
			}
			var outln = new mxOutline(graph, outline);
			
			
			
		},
		/**
		 * 创建右键快捷菜单
		 * @param menu 快捷菜单
		 * @param cell 当前右击选中的对象
		 * @param evt
		 */
		contextDesignerMenu: function(menu, cell, evt){
			//设置鼠标的位置
			Designer.setPoint(evt.x,evt.y);
			
			if (cell == null){
				//创建空白处右击菜单
				menu.addItem('创建开始节点', CONTEXT.contextPath+'/assets/wf/src/images/icons/start.png', function(eve){
					Ext.getCmp("startNode").toggle();
					var btn = Ext.getCmp("startNode");
					Designer.pressBtn = btn.id;
	        		Designer.cell_Type = btn.cellType;
	        		var sel_cell = Designer.createNode();
	        		Designer.showNodeInfo(sel_cell);
				});
				menu.addItem('创建结束节点', CONTEXT.contextPath+'/assets/wf/src/images/icons/end.png', function(){
					Ext.getCmp("endNode").toggle();
					var btn = Ext.getCmp("endNode");
					Designer.pressBtn = btn.id;
	        		Designer.cell_Type = btn.cellType;
	        		var sel_cell = Designer.createNode();
	        		Designer.showNodeInfo(sel_cell);
				});
				menu.addSeparator();
				menu.addItem('添加普通任务', CONTEXT.contextPath+'/assets/wf/src/images/icons/user.png', function(){
					Ext.getCmp("taskNode").toggle();
					var btn = Ext.getCmp("taskNode");
					Designer.pressBtn = btn.id;
	        		Designer.cell_Type = btn.cellType;
	        		var sel_cell = Designer.createNode();
	        		Designer.showNodeInfo(sel_cell);
				});
				menu.addItem('添加会签任务', CONTEXT.contextPath+'/assets/wf/src/images/icons/jointly_sign.png', function(){
					Ext.getCmp("jointlySignNode").toggle();
					var btn = Ext.getCmp("jointlySignNode");
					Designer.pressBtn = btn.id;
	        		Designer.cell_Type = btn.cellType;
	        		var sel_cell = Designer.createNode();
	        		Designer.showNodeInfo(sel_cell);
				});
				menu.addSeparator();
				menu.addItem('表单管理', CONTEXT.contextPath+'/assets/wf/src/images/icons/form.png', function(){
					WorkFlowForm.initWorkFlowFormWindow();
				});
				/*menu.addSeparator();
				menu.addItem('流程属性', CONTEXT.contextPath+'/assets/wf/src/images/icons/attr.png', function(){
					WorkFlowForm.createWorkFlowAttributeWindow();
				});*/
				return;
			}
			//创建选中节点快捷菜单
			menu.addItem('节点属性', CONTEXT.contextPath+'/assets/wf/src/images/icons/attr.png', function(){
				if(!cell.cellType){
					return;
				}
				if(cell.cellType == Designer.CONSTANTS.CELL_TYPES.LINE){
					Designer.createWorkFlowLineAttributeWindow(cell);
				}else{
					Designer.createWorkFlowNodeAttributeWindow(cell);
				}
			});
			if(cell.cellType != Designer.CONSTANTS.CELL_TYPES.LINE && cell.cellType != Designer.CONSTANTS.CELL_TYPES.END){
				//
				menu.addSeparator();
				menu.addItem('权限编辑', CONTEXT.contextPath+'/assets/wf/src/images/icons/rule.png', function(){
					Designer.createWorkFlowNodePermisWindow(cell);
				});
			}
		},
		/**
		 * 检查流程图是否已经创建了唯一的开始节点
		 * return true/false
		 */
		checkStartNode: function(){
			var isStart = false;
			//获取所有节点
			var cells = this.graph.getChildCells();
			for(i in cells){
				var cell = cells[i];
				/*if(cell.cellNodeType != "node"){
					continue;
				}*/
				if(cell.cellType == "start"){
					isStart = true;
					break;
				}
			}
			return isStart;
		},
		/**
		 * 检查流程图是否已经创建了唯一的结束节点
		 * return true/false
		 */
		checkEndNode: function(){
			var isEnd = false;
			//获取所有节点
			var cells = this.graph.getChildCells();
			for(i in cells){
				var cell = cells[i];
				/*if(cell.cellNodeType != "node"){
					continue;
				}*/
				if(cell.cellType == "end"){
					isEnd = true;
					break;
				}
			}
			return isEnd;
		},
		/**
		 * 创建节点
		 * @param x 坐标
		 * @param y 坐标
		 */
		createNode: function(text){
			// 在对象中创建默认组件
			var parent = this.graph.getDefaultParent();
			//在图形中插入组件
			//开启模型的事务
			this.graph.getModel().beginUpdate();
			var nodeStyle = "";
			var newNode = null;
			try {
				switch(Designer.cell_Type){
					case Designer.CONSTANTS.CELL_TYPES.START:{
						if(this.checkStartNode()){
							AjaxUtils.showError("已存在开始节点");
							return;
						}
						text = Designer.CONSTANTS.CELL_TYPES.START_NAME;
						nodeStyle = "ROUNDED;strokeColor=#0080c0;fillColor=#0080c0";
						break;
					}
					case Designer.CONSTANTS.CELL_TYPES.END:{
						if(this.checkEndNode()){
							AjaxUtils.showError("已存在结束节点");
							return;
						}
						text = Designer.CONSTANTS.CELL_TYPES.END_NAME;
						nodeStyle = "ROUNDED;strokeColor=#ff8040;fillColor=#ff8040";
						//nodeStyle = "shape=doubleEllipse;perimeter=ellipsePerimeter;";
						break;
					}
					case Designer.CONSTANTS.CELL_TYPES.JOINTLY:{
						text = Designer.CONSTANTS.CELL_TYPES.JOINTLY_NAME;
						break;
					}
					case Designer.CONSTANTS.CELL_TYPES.TASK:{
						text = Designer.CONSTANTS.CELL_TYPES.TASK_NAME;
						//nodeStyle = "shape=actor;perimeter=ellipsePerimeter";
						break;
					}
					default:{
						if(Ext.isEmpty(text)){
							text = Designer.CONSTANTS.CELL_TYPES.TASK_NAME;
						}
						break;
					}
				}
				//保证可以手动给线条添加折点
				newNode = this.graph.insertVertex(parent, null, text, this.getX(), this.getY(), 100, 50,nodeStyle);
				//设置节点类型
				newNode.cellType = Designer.cell_Type;
				//默认选中创建的节点
				Designer.graph.setSelectionCell(newNode);
				
				//添加新增节点
				this.addWorkFlowNode(Designer.cell_Type,newNode);
			}finally {
				//事务结束
				this.graph.getModel().endUpdate();
				Designer.cell_Type = null;
			}
			return newNode;
		},
		/**
		 * 添加流程图节点
		 */
		addWorkFlowNode: function(cellType,cellNode){
			if(cellType != Designer.CONSTANTS.CELL_TYPES.LINE){
				//任务节点
				var bkfmWorkFlowNode = new BkfmWorkFlowNode();
				bkfmWorkFlowNode.setNodeCode(cellNode.getId());
				bkfmWorkFlowNode.setNodeName(cellNode.value);
				bkfmWorkFlowNode.setWorkFlowCode(this.getBkfmWorkFlowConfig().getWorkFlowCode());
				bkfmWorkFlowNode.setNodePoints(cellNode.geometry.x+","+ cellNode.geometry.y+","+ cellNode.geometry.width+","+cellNode.geometry.height);
				bkfmWorkFlowNode.setNodeType(cellType);
				bkfmWorkFlowNode.setNodeFormName("");
				//添加新节点
				Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().addBkfmWorkFlowNode(bkfmWorkFlowNode);
			}
		},
		/**
		 * 更新任务节点信息
		 */
		updateWorkFlowNode: function(cellNode){
			if(!cellNode)	return;
			
			var bkfmWorkFlowNode = Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().getBkfmWorkFlowNode(cellNode.getId());
			if(bkfmWorkFlowNode ==null){
				return;
			}
			//任务节点
			bkfmWorkFlowNode.setNodeName(cellNode.value);
			bkfmWorkFlowNode.setNodePoints(cellNode.geometry.x+","+ cellNode.geometry.y+","+ cellNode.geometry.width+","+cellNode.geometry.height);
			//添加新节点
			Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().setBkfmWorkFlowNode(bkfmWorkFlowNode);
		},
		/**
		 * 添加连接线
		 */
		addWorkFlowLine: function(lineId,lineName,sourceNodeCode,sourceNodeName,targetNodeCode,targetNodeName,conditions){
			//添加连接线
			var bkfmFlowLine = new BkfmWorkFlowLine();
			bkfmFlowLine.setActionCode(lineId);
			bkfmFlowLine.setActionName(lineName);
			bkfmFlowLine.setSourceNodeCode(sourceNodeCode);
			bkfmFlowLine.setSourceNodeName(sourceNodeName);
			bkfmFlowLine.setTargetNodeCode(targetNodeCode);
			bkfmFlowLine.setTargetNodeName(targetNodeName);
			bkfmFlowLine.setConditions(conditions);
			Designer.getBkfmWorkFlowConfig().getWorkFlowLines().addBkfmWorkFlowLine(bkfmFlowLine);
		},
		/**
		 * 显示选中元素信息
		 */
		showNodeInfo: function(cellNode){
			if(!cellNode){
				Ext.getCmp("cellInfoForm").form.reset();
				return;
			}
			var node_code = cellNode.getId();
			var bkfmWorkFlowNode = Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().getBkfmWorkFlowNode(node_code);
			if(bkfmWorkFlowNode !=null){
				//任务节点
				Ext.getCmp("cellInfoForm").getForm().findField("cellNo").setValue(bkfmWorkFlowNode.getNodeCode());
				Ext.getCmp("cellInfoForm").getForm().findField("cellType").setValue(bkfmWorkFlowNode.getNodeType());
				Ext.getCmp("cellInfoForm").getForm().findField("cellText").setValue(bkfmWorkFlowNode.getNodeName());
				Ext.getCmp("cellInfoForm").getForm().findField("points").setValue(bkfmWorkFlowNode.getNodePoints());
			}else{
				//获取是否为连接线
				var bkfmFlowLine = Designer.getBkfmWorkFlowConfig().getWorkFlowLines().getBkfmWorkFlowLine(node_code);
				if(bkfmFlowLine !=null){
					//debugger;
					Ext.getCmp("cellInfoForm").getForm().findField("cellNo").setValue(bkfmFlowLine.getActionCode());
					Ext.getCmp("cellInfoForm").getForm().findField("cellType").setValue(Designer.CONSTANTS.CELL_TYPES.LINE);
					Ext.getCmp("cellInfoForm").getForm().findField("cellText").setValue(bkfmFlowLine.getActionName());
				}
			}
		},
		/**
		 * 删除节点
		 */
		deleteNode: function(cellNode){
			if(!cellNode){
				return;
			}
			AjaxUtils.showConfirm(function(){
				if (Designer.graph.isEnabled()) {
					//同时需要删除当前节点开始的所有的连接线,删除节点对应的表单配置信息，权限信息
					var cells = Designer.graph.getSelectionCells();
					for(i in cells){
						var cell = cells[i];
						//debugger;
						if(cell.cellType){
							if(cell.cellType == Designer.CONSTANTS.CELL_TYPES.LINE){
								//连接线
								var action_code = cell.getId();
								var workFlowLine = Designer.getBkfmWorkFlowConfig().getWorkFlowLines().getBkfmWorkFlowLine(action_code);
								Designer.getBkfmWorkFlowConfig().getWorkFlowLines().removeBkfmWorkFlowLine(workFlowLine);
							}else{
								//节点
								var node_code = cell.getId();
								//删除节点
								var bkfmWorkFlowNode = Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().getBkfmWorkFlowNode(node_code);
								Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().removeBkfmWorkFlowNode(bkfmWorkFlowNode);
								//获取节点相关的连接线
								 var workFlowLines = Designer.getBkfmWorkFlowConfig().getWorkFlowLines().getBkfmWorkFlowNodeLinesByNodeCode(bkfmWorkFlowNode);
								for(i in workFlowLines.getBkfmWorkFlowLines()){
									//删除连接线
									Designer.getBkfmWorkFlowConfig().getWorkFlowLines().removeBkfmWorkFlowLine(workFlowLines.getBkfmWorkFlowLines()[i]);
								}
							}
						}
					}
					//删除选中项
					Designer.graph.removeCells();
				}
			},"确定删除选中的节点?");
		},
		/**
		 * 创建流程节点属性窗体
		 */
		createWorkFlowNodeAttributeWindow: function(cellNode){
			var node_code = cellNode.getId();
			var bkfmWorkFlowNode = Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().getBkfmWorkFlowNode(node_code);
			var win = Ext.create('Ext.com.bkfm.window', {
				title : "节点属性",
				id: "wofkflow_node_attr_win",
				autoScroll : true,
				modal : true,
				height : Utils.getHeight()*0.5,
				width : Utils.getWidth()*0.5,
				items:[{
					xtype: "tabpanel",
					layout: 'fit',
					border: false,
					items:[{
						title: "基本信息",
						id: "base_node_attr_form",
						xtype: "form",
						layout: {
							type: "table",
							columns: 2,
							forceFit : true
						},
						bodyStyle:'padding:10px 10px 10px 10px;',
						items:[{
							xtype: "textfield",
							fieldLabel: "节点名称",
							id: "workflow_node_name",
							labelWidth: 80,
							value: bkfmWorkFlowNode.getNodeName(),
							style: "margin-right:5px"
						},Ext.create('Ext.form.ComboBox', {
							id: "node_form_name",
						    fieldLabel: '所属表单',
						    labelWidth: 80,
						    store: null,
						    queryMode: 'local',
							displayField: 'DISPLAYVALUE',
						    valueField: 'VALUE',
						    anchor: "100%",
						    editable: false,
						    listeners:{
						    	render: function(combox,opts){
						    		//初始化表单信息
						    		var data = [],dataValue=[];
						    		for(i in Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForms()){
						    			var bkfmWorkFlowForm = Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForms()[i];
						    			data.push({
				         			    	 VALUE: bkfmWorkFlowForm.getWorkFlowFormName(),
				         			    	 DISPLAYVALUE: bkfmWorkFlowForm.getWorkFlowFormName()
				         			    });
						    			dataValue.push(bkfmWorkFlowForm.getWorkFlowFormName());
						    		}
						    		
						    		var states = Ext.create('Ext.data.Store', {
						    		    fields: ['VALUE', 'DISPLAYVALUE'],
						    		    data: data
						    		});
						    		combox.store = states;
						    		
						    		//设置已经配置的表单
						    		if(!Ext.isEmpty(bkfmWorkFlowNode.getNodeFormName()) && Ext.Array.contains(dataValue,bkfmWorkFlowNode.getNodeFormName())){
						    			combox.setValue(bkfmWorkFlowNode.getNodeFormName());
						    			combox.setRawValue(bkfmWorkFlowNode.getNodeFormName());
						    		}
						    	}
						    }
						})]
					}]
				}],
				buttons:[{
					text: '保存',
					iconCls: "save",
					handler: function(){
						//节点名称
						var new_node_name = Ext.getCmp("base_node_attr_form").getForm().findField("workflow_node_name").getValue();
						//节点对应表单名称
						var new_node_form_name = Ext.getCmp("base_node_attr_form").getForm().findField("node_form_name").getValue();
						//重新设置节点名称
						if(new_node_name != bkfmWorkFlowNode.getNodeName()){
							bkfmWorkFlowNode.setNodeName(new_node_name);
							cellNode.valueChanged(new_node_name);
							Designer.graph.refresh(cellNode);
						}
						//重新设置节点对应表单名称
						if(new_node_form_name != bkfmWorkFlowNode.getNodeFormName()){
							bkfmWorkFlowNode.setNodeFormName(new_node_form_name);
						}
						//更新节点
						Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().setBkfmWorkFlowNode(bkfmWorkFlowNode);
						win.close();
					}
				},{
					text: "关闭",
					iconCls: "close",
					handler: function(){
						win.close();
					}
				}]
			});
			win.show();
		},
		/**
		 * 创建流程属性显示面板
		 */
		createWorkFlowAttributeWindow: function(){
			var win = Ext.create('Ext.com.bkfm.window', {
				title : "流程属性",
				id: "wofkflow_attr_win",
				autoScroll : true,
				modal : true,
				height : Utils.getHeight()*0.5,
				width : Utils.getWidth()*0.5,
				items:[{
					xtype: "tabpanel",
					layout: 'fit',
				}]
			});
		},
		/**
		 * 显示流程图连接线属性
		 */
		createWorkFlowLineAttributeWindow: function(cellNode){
			var action_code = cellNode.getId();
			var bkfmWorkFlowLine = Designer.getBkfmWorkFlowConfig().getWorkFlowLines().getBkfmWorkFlowLine(action_code);
			var win = Ext.create('Ext.com.bkfm.window', {
				title : "连接线属性",
				id: "wofkflow_line_attr_win",
				autoScroll : true,
				modal : true,
				height : Utils.getHeight()*0.5,
				width : Utils.getWidth()*0.5,
				items:[{
					xtype: "tabpanel",
					layout: 'fit',
					items:[{
						title: "基本信息",
						xtype: "form",
						id: "base_line_attr_form",
						layout: {
							type: "table",
							columns: 2,
							forceFit: true
						},
						bodyStyle:'padding:10px 10px 10px 10px;',						
						items:[{
							xtype: "textfield",
							fieldLabel: "连接线名称",
							id: "action_name",
							labelWidth: 80,
							value: bkfmWorkFlowLine.getActionName(),
							style: "margin-right:5px"
						}]
						
					},{
						title: "扭转条件"
					}]
				}],
				buttons:[{
					text: '保存',
					iconCls: "save",
					handler: function(){
						//保存节点所属表单
						var new_action_name = Ext.getCmp("base_line_attr_form").getForm().findField("action_name").getValue();
						if(new_action_name != bkfmWorkFlowLine.getActionName()){
							//保存节点名称
							cellNode.valueChanged(new_action_name);
							//刷新流程设计器
							Designer.graph.refresh(cellNode);
							//设置连接线名称
							bkfmWorkFlowLine.setActionName(new_action_name);
							Designer.getBkfmWorkFlowConfig().getWorkFlowLines().setBkfmWorkFlowLine(bkfmWorkFlowLine)
						}
						win.close();
					}
				},{
					text: "关闭",
					iconCls: "close",
					handler: function(){
						win.close();
					}
				}]
			}).show();
		},
		/**
		 * 创建工作流节点权限
		 */
		createWorkFlowNodePermisWindow: function(cellNode){
			var node_code = cellNode.getId();
			var bkfmWorkFlowNode = Designer.getBkfmWorkFlowConfig().getWorkFlowNodes().getBkfmWorkFlowNode(node_code);
			var bkfmWorkFlowConfig = Designer.getBkfmWorkFlowConfig();
			var win = Ext.create('Ext.com.bkfm.window', {
				title : "流程节点权限/事件配置",
				autoScroll : true,
				modal : true,
				height : Utils.getHeight()*0.5,
				width : Utils.getWidth()*0.5,
				items:[{
					xtype: 'tabpanel',
					items:[{
						title: "基本配置",
						layout: 'fit',
						items:[{
							xtype: 'form',
							id: "permis_base_form",
							border: false,
							layout: {
			                    type: 'vbox',
			                    align: 'stretch'
			                },
							bodyPadding:10,
							items:[{
								xtype: 'combo',
								id: "approvalPermisCombox",
								fieldLabel: "审批权限",
								labelAlign : 'right',
							    store: null,
							    queryMode: 'local',
								displayField: 'DISPLAYVALUE',
							    valueField: 'VALUE',
							    anchor: "100%",
							    editable: false,
								listeners:{
							    	render: function(combox,opts){
							    		var data = [{
						    		    	VALUE: bkfmWorkFlowNode.APPROVAL_PERMIS_ALL_USER_CODE,
						    		    	DISPLAYVALUE: bkfmWorkFlowNode.APPROVAL_PERMIS_ALL_USER_NAME
						    		    },{
						    		    	VALUE: bkfmWorkFlowNode.APPROVAL_PERMIS_APPOINT_PERMIS_CODE,
						    		    	DISPLAYVALUE: bkfmWorkFlowNode.APPROVAL_PERMIS_APPOINT_PERMIS_NAME
						    		    }];
							    		if(bkfmWorkFlowNode.getNodeType()==Designer.CONSTANTS.CELL_TYPES.START){
											combox.setFieldLabel("启动权限");
										}else if(bkfmWorkFlowNode.getNodeType()==Designer.CONSTANTS.CELL_TYPES.END){
											combox.setFieldLabel("");
											combox.hide();
										}else{
											combox.setFieldLabel("审批权限");
											data.push({
												VALUE: bkfmWorkFlowNode.APPROVAL_PERMIS_APPLY_USER_CODE,
							    		    	DISPLAYVALUE: bkfmWorkFlowNode.APPROVAL_PERMIS_APPLY_USER_NAME
											});
										}
							    		if(combox.isHidden()){
							    			return ;
							    		}
							    		
							    		var states = Ext.create('Ext.data.Store', {
							    		    fields: ['VALUE', 'DISPLAYVALUE'],
							    		    data: data
							    		});
							    		combox.store = states;
							    		//设置配置值
							    		combox.setValue(bkfmWorkFlowNode.getApprovalPermis());
							    		
							    	},
							    	change: function(combox,newValue,oldValue,opts){
							    		var tabPanel = combox.ownerCt.ownerCt.ownerCt;
							    		if(newValue == bkfmWorkFlowNode.APPROVAL_PERMIS_ALL_USER_CODE || newValue == bkfmWorkFlowNode.APPROVAL_PERMIS_APPLY_USER_CODE){
							    			//申请人或者所有人
							    			for(i in tabPanel.items.items){
							    				if(i>0){
							    					var item = tabPanel.items.items[i]
							    					item.tab.hide()
							    				}
							    			}
							    		}else{
							    			for(i in tabPanel.items.items){
							    				if(i>0){
							    					var item = tabPanel.items.items[i]
							    					item.tab.show();
							    				}
							    			}
							    		}
							    	}
								}
							},{
								xtype: "textfield",
								fieldLabel: '节点前事件',
								id: "beforeActionHandler",
								labelAlign : 'right',
								anchor: "100%",
							},{
								xtype: "textfield",
								fieldLabel: '节点后事件',
								id: "afterActionHandler",
								labelAlign : 'right',
								anchor: "100%",
							}],
							listeners:{
								afterrender: function(form,opts){
									var beforeActionHandlerField = form.queryById("beforeActionHandler");
									var afterActionHandlerField = form.queryById("afterActionHandler");
									if(bkfmWorkFlowNode.getNodeType()==Designer.CONSTANTS.CELL_TYPES.START){
										beforeActionHandlerField.hide();
									}else if(bkfmWorkFlowNode.getNodeType()==Designer.CONSTANTS.CELL_TYPES.END){
										beforeActionHandlerField.hide();
										afterActionHandlerField.hide();
									}
									beforeActionHandlerField.setValue(bkfmWorkFlowNode.getBeforeActionHandler());
									afterActionHandlerField.setValue(bkfmWorkFlowNode.getAfterActionHandler());
								}
							}
						}]
					},{
						title: '人员权限',
						layout: 'fit',
						hidden: true,
						items:[Ext.create('Ext.com.bkfm.datagrid', {
							objPath : "ROOT/WORKFLOW/PERMIS/BLK_NODE_PERMIS_USERS",
							border: false,
							showstandardBtn: false,
							paging: false,
							loadAuto: false,
							hiddenField:['WORKFLOW_DEPLOYED_ID'],
							listeners:{
								render: function(selfGrid,eOpts){
									//默认初始化显示配置人员信息
									var records = bkfmWorkFlowNode.getPermisUsers().getBkfmWorkFlowNodePermisUsers();
									for(i in records){
										var bkfmWorkFlowNodePermisUser = records[i];
										//添加到用户grid中
										var newRecord = Ext.create(selfGrid.modelField,{});
										//设置记录状态为新增
										newRecord.state = Constants.RECORD_NEW;
										var rowIndex = selfGrid.getStore().getCount();
										selfGrid.getStore().insert(rowIndex,newRecord);
										newRecord.set("USER_NO",bkfmWorkFlowNodePermisUser.getUserNo());
										newRecord.set("USER_NO_DISPLAYVALUE",bkfmWorkFlowNodePermisUser.getUserName());
										newRecord.set("NODE_CODE",bkfmWorkFlowNodePermisUser.getNodeCode());
										newRecord.set("NODE_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisUser.getNodeName());
										newRecord.set("WORKFLOW_CODE",bkfmWorkFlowNodePermisUser.getWorkFlowCode());
										newRecord.set("WORKFLOW_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisUser.getWorkFlowName());
									}
								}
							},
							tbar:[{
								text: '添加',
								iconCls: 'add',
								handler: function(self){
									var selfGrid = self.ownerCt.ownerCt;
									Utils.showUserWin(function(records){
										for(i in records){
											var record = records[i];
											//创建用户权限对象
											var bkfmWorkFlowNodePermisUser = new BkfmWorkFlowNodePermisUser();
											bkfmWorkFlowNodePermisUser.setUserNo(record.get("USER_NO"));
											bkfmWorkFlowNodePermisUser.setUserName(record.get("USER_NAME"));
											bkfmWorkFlowNodePermisUser.setNodeCode(bkfmWorkFlowNode.getNodeCode());
											bkfmWorkFlowNodePermisUser.setNodeName(bkfmWorkFlowNode.getNodeName());
											bkfmWorkFlowNodePermisUser.setWorkFlowCode(bkfmWorkFlowConfig.getWorkFlowCode());
											bkfmWorkFlowNodePermisUser.setWorkFlowName(bkfmWorkFlowConfig.getWorkFlowName());
											if(bkfmWorkFlowNode.getPermisUsers().hasExistsUser(bkfmWorkFlowNodePermisUser.getUserNo(),bkfmWorkFlowNodePermisUser.getNodeCode())){
												continue;
											}
											//添加到用户grid中
											var newRecord = Ext.create(selfGrid.modelField,{});
											//设置记录状态为新增
											newRecord.state = Constants.RECORD_NEW;
											var rowIndex = selfGrid.getStore().getCount();
											selfGrid.getStore().insert(rowIndex,newRecord);
											newRecord.set("USER_NO",bkfmWorkFlowNodePermisUser.getUserNo());
											newRecord.set("USER_NO_DISPLAYVALUE",bkfmWorkFlowNodePermisUser.getUserName());
											newRecord.set("NODE_CODE",bkfmWorkFlowNodePermisUser.getNodeCode());
											newRecord.set("NODE_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisUser.getNodeName());
											newRecord.set("WORKFLOW_CODE",bkfmWorkFlowNodePermisUser.getWorkFlowCode());
											newRecord.set("WORKFLOW_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisUser.getWorkFlowName());
											//添加到用户权限列表中
											bkfmWorkFlowNode.getPermisUsers().addBkfmWorkFlowNodePermisUser(bkfmWorkFlowNodePermisUser);
										}
									});
								}
							},{
								text: '删除',
								iconCls: 'delete',
								handler: function(self){
									var selfGrid = self.ownerCt.ownerCt;
									//删除用户权限列表中的对应用户数据
									var records = selfGrid.getSelectedRecords();
									for(i in records){
										//根据用户编码删除用户对象
										var user_no = records[i].get("USER_NO");
										var node_code = records[i].get("NODE_CODE");
										bkfmWorkFlowNode.getPermisUsers().removeBkfmWorkFlowNodePermisUserByUserNo(user_no,node_code);
									}
									//删除表格选中记录
									selfGrid.deleteRecords();
								}
							}]	
						})]
					},{
						title: '角色权限',
						layout: 'fit',
						hidden: true,
						items:[Ext.create('Ext.com.bkfm.datagrid', {
							objPath : "ROOT/WORKFLOW/PERMIS/BLK_NODE_PERMIS_ROLES",
							border: false,
							showstandardBtn: false,
							paging: false,
							loadAuto: false,
							hiddenField:['WORKFLOW_DEPLOYED_ID'],
							listeners:{
								render: function(selfGrid,eOpts){
									var records = bkfmWorkFlowNode.getPermisRoles().getBkfmWorkFlowNodePermisRoles();
									for(i in records){
										var bkfmWorkFlowNodePermisRole = records[i];
										//添加到角色grid中
										var newRecord = Ext.create(selfGrid.modelField,{});
										//设置记录状态为新增
										newRecord.state = Constants.RECORD_NEW;
										var rowIndex = selfGrid.getStore().getCount();
										selfGrid.getStore().insert(rowIndex,newRecord);
										newRecord.set("ROLE_ID",bkfmWorkFlowNodePermisRole.getRoleId());
										newRecord.set("ROLE_ID_DISPLAYVALUE",bkfmWorkFlowNodePermisRole.getRoleName());
										newRecord.set("NODE_CODE",bkfmWorkFlowNodePermisRole.getNodeCode());
										newRecord.set("NODE_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisRole.getNodeName());
										newRecord.set("WORKFLOW_CODE",bkfmWorkFlowNodePermisRole.getWorkFlowCode());
										newRecord.set("WORKFLOW_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisRole.getWorkFlowName());
									}
								}
							},
							tbar:[{
								text: '添加',
								iconCls: 'add',
								handler: function(self){
									var selfGrid = self.ownerCt.ownerCt;
									Utils.showRoleWin(function(records){
										for(i in records){
											var record = records[i];
											var bkfmWorkFlowNodePermisRole = new BkfmWorkFlowNodePermisRole();
											bkfmWorkFlowNodePermisRole.setRoleId(record.getId());
											bkfmWorkFlowNodePermisRole.setRoleName(record.get("ROLE_NAME"));
											bkfmWorkFlowNodePermisRole.setNodeCode(bkfmWorkFlowNode.getNodeCode());
											bkfmWorkFlowNodePermisRole.setNodeName(bkfmWorkFlowNode.getNodeName());
											bkfmWorkFlowNodePermisRole.setWorkFlowCode(bkfmWorkFlowConfig.getWorkFlowCode());
											bkfmWorkFlowNodePermisRole.setWorkFlowName(bkfmWorkFlowConfig.getWorkFlowName());
											if(bkfmWorkFlowNode.getPermisRoles().hasExistsRole(bkfmWorkFlowNodePermisRole.getRoleId(),bkfmWorkFlowNodePermisRole.getNodeCode())){
												//重复的角色不再次添加
												continue;
											}
											
											//添加到角色grid中
											var newRecord = Ext.create(selfGrid.modelField,{});
											//设置记录状态为新增
											newRecord.state = Constants.RECORD_NEW;
											var rowIndex = selfGrid.getStore().getCount();
											selfGrid.getStore().insert(rowIndex,newRecord);
											newRecord.set("ROLE_ID",bkfmWorkFlowNodePermisRole.getRoleId());
											newRecord.set("ROLE_ID_DISPLAYVALUE",bkfmWorkFlowNodePermisRole.getRoleName());
											newRecord.set("NODE_CODE",bkfmWorkFlowNodePermisRole.getNodeCode());
											newRecord.set("NODE_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisRole.getNodeName());
											newRecord.set("WORKFLOW_CODE",bkfmWorkFlowNodePermisRole.getWorkFlowCode());
											newRecord.set("WORKFLOW_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisRole.getWorkFlowName());
											//添加到角色权限列表中
											bkfmWorkFlowNode.getPermisRoles().addBkfmWorkFlowNodePermisRole(bkfmWorkFlowNodePermisRole);
										}
									});
								}
							},{
								text: '删除',
								iconCls: 'delete',
								handler: function(self){
									var selfGrid = self.ownerCt.ownerCt;
									//删除用户权限列表中的对应用户数据
									var records = selfGrid.getSelectedRecords();
									for(i in records){
										//根据用户编码删除用户对象
										var role_id = records[i].get("ROLE_ID");
										var node_code = records[i].get("NODE_CODE");
										bkfmWorkFlowNode.getPermisRoles().removeBkfmWorkFlowNodePermisRole(role_id,node_code);
									}
									//删除表格选中记录
									selfGrid.deleteRecords();
								}
							}]
						})]
					},{
						title: '部门权限',
						layout: 'fit',
						hidden: true,
						items:[Ext.create('Ext.com.bkfm.datagrid', {
							objPath : "ROOT/WORKFLOW/PERMIS/BLK_NODE_PERMIS_DEPTS",
							border: false,
							showstandardBtn: false,
							paging: false,
							loadAuto: false,
							hiddenField:['WORKFLOW_DEPLOYED_ID'],
							listeners:{
								render: function(selfGrid,eOpts){
									var records = bkfmWorkFlowNode.getPermisDepts().getBkfmWorkFlowNodePermisDepts();
									for(i in records){
										var bkfmWorkFlowNodePermisDept = records[i];
										//添加到角色grid中
										var newRecord = Ext.create(selfGrid.modelField,{});
										//设置记录状态为新增
										newRecord.state = Constants.RECORD_NEW;
										var rowIndex = selfGrid.getStore().getCount();
										selfGrid.getStore().insert(rowIndex,newRecord);
										newRecord.set("ORG_ID",bkfmWorkFlowNodePermisDept.getOrgId());
										newRecord.set("ORG_ID_DISPLAYVALUE",bkfmWorkFlowNodePermisDept.getOrgName());
										newRecord.set("NODE_CODE",bkfmWorkFlowNodePermisDept.getNodeCode());
										newRecord.set("NODE_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisDept.getNodeName());
										newRecord.set("WORKFLOW_CODE",bkfmWorkFlowNodePermisDept.getWorkFlowCode());
										newRecord.set("WORKFLOW_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisDept.getWorkFlowName());
									}
								}
							},
							tbar:[{
								text: '添加',
								iconCls: 'add',
								handler: function(self){
									var selfGrid = self.ownerCt.ownerCt;
									Utils.showOrgWin(function(records){
										for(i in records){
											var record = records[i];
											var bkfmWorkFlowNodePermisDept = new BkfmWorkFlowNodePermisDept();
											bkfmWorkFlowNodePermisDept.setOrgId(record.getId());
											bkfmWorkFlowNodePermisDept.setOrgName(record.get("org_name"));
											bkfmWorkFlowNodePermisDept.setNodeCode(bkfmWorkFlowNode.getNodeCode());
											bkfmWorkFlowNodePermisDept.setNodeName(bkfmWorkFlowNode.getNodeName());
											bkfmWorkFlowNodePermisDept.setWorkFlowCode(bkfmWorkFlowConfig.getWorkFlowCode());
											bkfmWorkFlowNodePermisDept.setWorkFlowName(bkfmWorkFlowConfig.getWorkFlowName());
											if(bkfmWorkFlowNode.getPermisDepts().hasExistsDept(bkfmWorkFlowNodePermisDept.getOrgId(),bkfmWorkFlowNodePermisDept.getNodeCode())){
												//重复的角色不再次添加
												continue;
											}
											
											//添加到角色grid中
											var newRecord = Ext.create(selfGrid.modelField,{});
											//设置记录状态为新增
											newRecord.state = Constants.RECORD_NEW;
											var rowIndex = selfGrid.getStore().getCount();
											selfGrid.getStore().insert(rowIndex,newRecord);
											newRecord.set("ORG_ID",bkfmWorkFlowNodePermisDept.getOrgId());
											newRecord.set("ORG_ID_DISPLAYVALUE",bkfmWorkFlowNodePermisDept.getOrgName());
											newRecord.set("NODE_CODE",bkfmWorkFlowNodePermisDept.getNodeCode());
											newRecord.set("NODE_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisDept.getNodeName());
											newRecord.set("WORKFLOW_CODE",bkfmWorkFlowNodePermisDept.getWorkFlowCode());
											newRecord.set("WORKFLOW_CODE_DISPLAYVALUE",bkfmWorkFlowNodePermisDept.getWorkFlowName());
											//添加到角色权限列表中
											bkfmWorkFlowNode.getPermisDepts().addBkfmWorkFlowNodePermisDept(bkfmWorkFlowNodePermisDept);
										}
									});
									
								}
							},{
								text: '删除',
								iconCls: 'delete',
								handler: function(self){
									var selfGrid = self.ownerCt.ownerCt;
									//删除用户权限列表中的对应用户数据
									var records = selfGrid.getSelectedRecords();
									for(i in records){
										//根据用户编码删除用户对象
										var org_id = records[i].get("ORG_ID");
										var node_code = records[i].get("NODE_CODE");
										bkfmWorkFlowNode.getPermisDepts().removeBkfmWorkFlowNodePermisDept(org_id,node_code);
									}
									//删除表格选中记录
									selfGrid.deleteRecords();
								}
							}]
						})]
					}],
					buttons:[{
						text: '关闭',
						iconCls: 'close',
						handler: function(){
							//保存基本配置
							var permisBaseForm = Ext.getCmp("permis_base_form");
							//设置审批人/启动人
							bkfmWorkFlowNode.setApprovalPermis(permisBaseForm.queryById("approvalPermisCombox").getValue());
							//设置操作前事件
							bkfmWorkFlowNode.setBeforeActionHandler(permisBaseForm.queryById("beforeActionHandler").getValue());
							//设置操作后事件
							bkfmWorkFlowNode.setAfterActionHandler(permisBaseForm.queryById("afterActionHandler").getValue());
							
							win.close();
						}
					}]
				}]
			});
			win.show();
		}
};

/**
 * 表单管理
 */
var WorkFlowForm = {
		/**
		 * 初始化表单管理器
		 */
		initWorkFlowFormWindow: function(){
			/**
			 * 获取流程信息
			 */
			var bkfmWorkFlowConfig = Designer.getBkfmWorkFlowConfig();
			
			var win = Ext.create('Ext.com.bkfm.window', {
				title : "表单配置器",
				autoScroll : true,
				modal : true,
				height : Utils.getHeight()*0.95,
				width : Utils.getWidth()*0.95,
				items:[{
					xtype: 'tabpanel',
					border: false,
					layout: 'fit',
					//id: "formConfigPanel",
					activeTab: 0,
					listeners:{
						tabchange:function (tab, n) {
							if(tab.getActiveTab().title=="业务表配置"){
								return;
							}
							if(Designer.getBkfmWorkFlowTables().getWorkFlowTables().length ==0){
								AjaxUtils.showError("请先配置业务表");
								tab.setActiveTab(0);
							}else if(!Designer.getBkfmWorkFlowTables().hashExistsMainTable()){
								AjaxUtils.showError("请先配置业务主表");
								tab.setActiveTab(0);
							}
						}
					},
					items:[{
						title: '业务表配置',
	                	layout: 'fit',
	                	items:[Ext.create('Ext.com.bkfm.datagrid', {
							objPath : "ROOT/WORKFLOW/LCGL/BLK_WORKFLOW_TABLES",
							border: true,
							showstandardBtn: false,
							paging: false,
							loadAuto: false,
							listeners:{
								render: function(selfGrid,opts){
									var records = Designer.getBkfmWorkFlowTables().getWorkFlowTables();
									for(i in records){
										var bkfmWorkFlowTable = records[i];
										//添加到角色grid中
										var newRecord = Ext.create(selfGrid.modelField,{});
										//设置记录状态为新增
										newRecord.state = Constants.RECORD_NEW;
										var rowIndex = selfGrid.getStore().getCount();
										selfGrid.getStore().insert(rowIndex,newRecord);
										newRecord.set("WORKFLOW_CODE",bkfmWorkFlowTable.getWorkFlowCode());
										newRecord.set("WORKFLOW_CODE_DISPLAYVALUE",bkfmWorkFlowTable.getWorkFlowName());
										newRecord.set("TABLE_PATH",bkfmWorkFlowTable.getTablePath());
										newRecord.set("TABLE_PATH_DISPLAYVALUE",bkfmWorkFlowTable.getTableName());
										newRecord.set("TABLE_TYPE",bkfmWorkFlowTable.getTableType());
										newRecord.set("TABLE_TYPE_DISPLAYVALUE",bkfmWorkFlowTable.getTableTypeName());
									}
								}
							},
							tbar:[{
								text: '配置主表',
								iconCls: 'key',
								handler: function(self){
									var selfGrid = self.ownerCt.ownerCt;
									if(Designer.getBkfmWorkFlowTables().hashExistsMainTable()){
										AjaxUtils.showError("主表已配置，不可重复配置");
										return;
									}
									WorkFlowForm.createTableTree(function(record){
										//创建主表对象
										var bkfmWorkFlowTable = new BkfmWorkFlowTable();
										bkfmWorkFlowTable.setWorkFlowCode(bkfmWorkFlowConfig.getWorkFlowCode());
										bkfmWorkFlowTable.setWorkFlowName(bkfmWorkFlowConfig.getWorkFlowName());
										bkfmWorkFlowTable.setTablePath(record.raw.obj_path);
										bkfmWorkFlowTable.setTableName(record.raw.text);
										bkfmWorkFlowTable.setTableType(bkfmWorkFlowTable.MAINTABLE_CODE);
										bkfmWorkFlowTable.setTableTypeName(bkfmWorkFlowTable.MAINTABLE_NAME);
										if(Designer.getBkfmWorkFlowTables().getWorkFlowTable(bkfmWorkFlowTable.getTablePath()) !=null){
											AjaxUtils.showError("“"+bkfmWorkFlowTable.getTableName()+"”已经存在，无需重复配置!");
											return;
										}
										//添加到角色grid中
										var newRecord = Ext.create(selfGrid.modelField,{});
										//设置记录状态为新增
										newRecord.state = Constants.RECORD_NEW;
										var rowIndex = selfGrid.getStore().getCount();
										selfGrid.getStore().insert(rowIndex,newRecord);
										newRecord.set("WORKFLOW_CODE",bkfmWorkFlowTable.getWorkFlowCode());
										newRecord.set("WORKFLOW_CODE_DISPLAYVALUE",bkfmWorkFlowTable.getWorkFlowName());
										newRecord.set("TABLE_PATH",bkfmWorkFlowTable.getTablePath());
										newRecord.set("TABLE_PATH_DISPLAYVALUE",bkfmWorkFlowTable.getTableName());
										newRecord.set("TABLE_TYPE",bkfmWorkFlowTable.getTableType());
										newRecord.set("TABLE_TYPE_DISPLAYVALUE",bkfmWorkFlowTable.getTableTypeName());
										
										Designer.getBkfmWorkFlowTables().addWorkFlowTable(bkfmWorkFlowTable);
									});
								}
							},{
								text: '配置明细表',
								iconCls: 'addTable',
								handler: function(self){
									var selfGrid = self.ownerCt.ownerCt;
									WorkFlowForm.createTableTree(function(record){
										//创建主表对象
										var bkfmWorkFlowTable = new BkfmWorkFlowTable();
										bkfmWorkFlowTable.setWorkFlowCode(bkfmWorkFlowConfig.getWorkFlowCode());
										bkfmWorkFlowTable.setWorkFlowName(bkfmWorkFlowConfig.getWorkFlowName());
										bkfmWorkFlowTable.setTablePath(record.raw.obj_path);
										bkfmWorkFlowTable.setTableName(record.raw.text);
										bkfmWorkFlowTable.setTableType(bkfmWorkFlowTable.SCHEDULETABLE_CODE);
										bkfmWorkFlowTable.setTableTypeName(bkfmWorkFlowTable.SCHEDULETABLE_NAME);
										if(Designer.getBkfmWorkFlowTables().getWorkFlowTable(bkfmWorkFlowTable.getTablePath()) !=null){
											AjaxUtils.showError("“"+bkfmWorkFlowTable.getTableName()+"”已经存在，无需重复配置!");
											return;
										}
										//添加到角色grid中
										var newRecord = Ext.create(selfGrid.modelField,{});
										//设置记录状态为新增
										newRecord.state = Constants.RECORD_NEW;
										var rowIndex = selfGrid.getStore().getCount();
										selfGrid.getStore().insert(rowIndex,newRecord);
										newRecord.set("WORKFLOW_CODE",bkfmWorkFlowTable.getWorkFlowCode());
										newRecord.set("WORKFLOW_CODE_DISPLAYVALUE",bkfmWorkFlowTable.getWorkFlowName());
										newRecord.set("TABLE_PATH",bkfmWorkFlowTable.getTablePath());
										newRecord.set("TABLE_PATH_DISPLAYVALUE",bkfmWorkFlowTable.getTableName());
										newRecord.set("TABLE_TYPE",bkfmWorkFlowTable.getTableType());
										newRecord.set("TABLE_TYPE_DISPLAYVALUE",bkfmWorkFlowTable.getTableTypeName());
										
										Designer.getBkfmWorkFlowTables().addWorkFlowTable(bkfmWorkFlowTable);
									});
								}
							},{
								text: '删除',
								iconCls: 'delete',
								handler: function(){
									AjaxUtils.showConfirm(function(){
										
									},"确定需要删除该业务表配置项？确定删除后关联的表单配置页面的相关配置模块将同时删除！");
								}
							}]
	                	})]
					},{
						title: '表单设计',
						xtype: 'panel',
						border: false,
						layout: {
			                type: 'border'
			            },
			            items:[{
			            	region: 'west',
			                width: Utils.getWidth()*0.15,
			                border: false,
			                layout: 'fit',
			                items:[WorkFlowForm.createWorkFlowFormPanel()]
			            },{
			            	region: 'center',
			            	border: false,
			            	layout: 'fit',
			            	items:[Ext.create('Ext.com.bkfm.Portal', {
			            		//id: 'portalFrame',
			            		autoScroll: true,
			            		tbar:[{
	                    			text: '添加表单',
	                    			iconCls: 'addForm',
	                    			handler: function(self){
	                    				var tree = Ext.getCmp("workFlowFormTree");
	                    				var node = tree.getSelectNode();
	                            		if(node==null || node.isRoot()){
	                            			AjaxUtils.showError("请选择或者创建需要配置的表单选项");
	                            			return;
	                            		}
	                            		var selfPortal = self.ownerCt.ownerCt;
	                            		WorkFlowForm.openWorkFlowTableWin(function(records,win){
	                            			for(i in records){
	                            				var record = records[i];
	                            				var bkfmWorkFlowFormPageItem = new BkfmWorkFlowFormPageItem();
	                            				bkfmWorkFlowFormPageItem.setWorkFlowFormName(node.get("text"));
	                            				bkfmWorkFlowFormPageItem.setPageItemType(bkfmWorkFlowFormPageItem.PAGEITEM_TYPE_FORM_CODE);
	                            				bkfmWorkFlowFormPageItem.setPageTypeName(bkfmWorkFlowFormPageItem.PAGEITEM_TYPE_FORM_NAME);
	                            				bkfmWorkFlowFormPageItem.setPageTitle(record.get("TABLE_PATH_DISPLAYVALUE"));
	                            				bkfmWorkFlowFormPageItem.setTablePath(record.get("TABLE_PATH"));
	                            				bkfmWorkFlowFormPageItem.setTableName(record.get("TABLE_PATH_DISPLAYVALUE"));
	                            				bkfmWorkFlowFormPageItem.setPageItemFormColumnCount(bkfmWorkFlowFormPageItem.DEFAULT_FORM_COLUMNCOUNT);
	                            				WorkFlowForm.addWorkFlowPageItem(bkfmWorkFlowFormPageItem,false);
	                            				//重新设置排序位置
	                            				Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(bkfmWorkFlowFormPageItem.getWorkFlowFormName()).sortForm();
	                            			}
	                            			win.close();
	                            		});
	                    			}
			            		},{
			            			text: '添加表格',
	                    			iconCls: 'addTable',
	                    			handler: function(self){
	                    				var tree = Ext.getCmp("workFlowFormTree");
	                    				var node = tree.getSelectNode();
	                            		if(node==null || node.isRoot()){
	                            			AjaxUtils.showError("请选择或者创建需要配置的表单选项");
	                            			return;
	                            		}
	                            		var selfPortal = self.ownerCt.ownerCt;
	                            		WorkFlowForm.openWorkFlowTableWin(function(records,win){
	                            			for(i in records){
	                            				var record = records[i];
	                            				var bkfmWorkFlowFormPageItem = new BkfmWorkFlowFormPageItem();
	                            				bkfmWorkFlowFormPageItem.setWorkFlowFormName(node.get("text"));
	                            				bkfmWorkFlowFormPageItem.setPageItemType(bkfmWorkFlowFormPageItem.PAGEITEM_TYPE_GRID_CODE);
	                            				bkfmWorkFlowFormPageItem.setPageTypeName(bkfmWorkFlowFormPageItem.PAGEITEM_TYPE_GRID_NAME);
	                            				bkfmWorkFlowFormPageItem.setPageTitle(record.get("TABLE_PATH_DISPLAYVALUE"));
	                            				bkfmWorkFlowFormPageItem.setTablePath(record.get("TABLE_PATH"));
	                            				bkfmWorkFlowFormPageItem.setTableName(record.get("TABLE_PATH_DISPLAYVALUE"));
	                            				bkfmWorkFlowFormPageItem.setPageItemFormColumnCount(bkfmWorkFlowFormPageItem.DEFAULT_FORM_COLUMNCOUNT);
	                            				WorkFlowForm.addWorkFlowPageItem(bkfmWorkFlowFormPageItem,false);
	                            				//重新设置排序位置
	                            				Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(bkfmWorkFlowFormPageItem.getWorkFlowFormName()).sortForm();
	                            			}
	                            			win.close();
	                            		});
	                    			}
			            		},'->',{
			            			text: '预览',
	                    			iconCls: 'view',
	                    			handler: function(self){
	                    				var tree = Ext.getCmp("workFlowFormTree");
	                    				var node = tree.getSelectNode();
	                            		if(node==null || node.isRoot()){
	                            			AjaxUtils.showError("请选择或者创建需要配置的表单选项");
	                            			return;
	                            		}
	                            		var workflow_form_name = node.get("text");
	                            		WorkFlowForm.viewWorkFlowPageItems(workflow_form_name);
	                    			}
			            		}],
			            		items:[{
		                    		xtype: 'portalpanel',
		                    		layout:'fit',
		                    		border: false,
		                    		style: 'padding:10px',
		                    		autoScroll: true,
		                    		items:[{
		                    			id: 'formDesignerPanel',
		                    			layout:'fit',
		                    			items: []
		                    			
		                    		}],
			            		}]
			            	})]
			            }]
					}]
				}]
			});
			win.show();
		},
		/**
		 * 关闭
		 */
		onPortletClose: function(portal){
			debugger;
    		AjaxUtils.showConfirm(function(){
    			//获取选择的表单页面具体的配置项元素
    			var bkfmWorkFlowFormPageItem = portal.items.get(0).getBkfmWorkFlowFormPageItem();
    			//删除
    			Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(bkfmWorkFlowFormPageItem.getWorkFlowFormName()).getWorkFlowFormPageItems().removeBkfmWorkFlowFormPageItem(bkfmWorkFlowFormPageItem.getWorkFlowFormName(),bkfmWorkFlowFormPageItem.getTablePath());;
    			//页面删除显示项
    			Ext.getCmp("formDesignerPanel").remove(portal);
    			//重新设置排序位置
				Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(bkfmWorkFlowFormPageItem.getWorkFlowFormName()).sortForm();
    			
			},"确定需要删除“"+portal.title+"”模块？");
		},
		/**
		 * 打开业务表选择窗体
		 */
		createTableTree: function(callbackFn){
			var win = Ext.create('Ext.com.bkfm.window', {
				title : "业务表",
				autoScroll : true,
				modal : true,
				height : Utils.getHeight()*0.8,
				width : Utils.getWidth()*0.25,
				items: [Ext.create("Ext.com.bkfm.tree",{
			 		rootVisible: true,
			 		rootLabel: "业务模型",
			 		treeConfigId: "modelTree",
			 		rootTreeId: "00000000000000000000000000000001",
			 		border: false,
			 		autoScroll: true,
			 		tbar:['业务表名：',{
			 			xtype: 'textfield',
			 			id: 'model_name'
			 		},{
			 			text: '查询',
			 			iconCls: 'search',
			 			handler: function(self){
			 				var tree = self.ownerCt.ownerCt;
			 				var modelName = Ext.getCmp("model_name").getValue();
			 				tree.filterByText(modelName);
			 			}
			 		}],
			 		listeners:{
			 			itemclick: function(view,record,item,index,e,opts){
			 				Ext.callback(callbackFn,this,[record]);
			 				win.close();
			 			}
			 		}
				})]
			}).show();
		},
		/**
		 * 创建流程表单面板，在该面板中可以增、删、改流程表单
		 */
		createWorkFlowFormPanel: function(){
			var store = Ext.create('Ext.data.TreeStore', {
			    root: {
			        expanded: true,
			        text : "流程表单"
			    }
			});
			var tree = Ext.create('Ext.com.bkfm.tree', {
				id: 'workFlowFormTree',
			    width: 200,
			    height: 150,
			    store: store,
			    rootVisible: true,
			    dataSource: 'local',
                tbar:[{
                	text: '新建',
                	iconCls: 'add',
                	handler: function(){
                		WorkFlowForm.createNewWorkFlowForm();
                	}
                },{
                	text: '删除',
                	iconCls: 'delete',
                	handler: function(self){
                		var tree = self.ownerCt.ownerCt;
                		var node = tree.getSelectNode();
                		if(node.isRoot()){
                			return;
                		}
		        		AjaxUtils.showConfirm(function(){
		        			//删除节点
		        			tree.getRootNode().removeChild(node);
		        			//删除存储节点数据
		        			Designer.getBkfmWorkFlowForms().removeBkfmWorkFlowForm(node.get("text"));
						},"确定需要删除选中的表单?");
                		
                	}
                }],
                listeners:{
                	render: function(selfTree){
                		var records = Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForms();
                		for(i in records){
                			var bkfmWorkFlowForm = records[i];
                			var newNode = Ext.create('Ext.data.NodeInterface',{
         			    	   leaf:false
         			       });
         			       var newNode =  selfTree.getRootNode().createNode(newNode);
         		           newNode.set("text",bkfmWorkFlowForm.getWorkFlowFormName());
         		           newNode.set("leaf",false);
         		          selfTree.getRootNode().appendChild(newNode)
                		}
                	},
	                itemclick: function(view,node,item,index,e,opts){
	                	Ext.getCmp("formDesignerPanel").removeAll();
	    				if(node.isRoot()){
	    					return;
	    				}
	                	//debugger;
	                	//点击表单选项，重新再portal面板中构建最新的表单页面配置项
						//获取流程表单名称
						var workflow_form_name = node.get("text");
						//根据表单名称获取当前表单页面已经配置的配置项列表
						var pageItems = Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(workflow_form_name).getWorkFlowFormPageItems().getBkfmWorkFlowFormPageItems();
						for(i in pageItems){
							var bkfmWorkFlowFormPageItem = pageItems[i];
							WorkFlowForm.addWorkFlowPageItem(bkfmWorkFlowFormPageItem,true);
						}
	                }
                }
			});
			
			return tree;
		},
		/**
		 * 新建流程表单
		 */
		createNewWorkFlowForm: function(){
			/**
			 * 获取流程信息
			 */
			var bkfmWorkFlowConfig = Designer.getBkfmWorkFlowConfig();
			
			Ext.Msg.prompt('输入提示', '输入表单名称:', function(btn, text){
			    if (btn == 'ok'){
			       var tree = Ext.getCmp("workFlowFormTree");
			       for(i in tree.getRootNode().childNodes){
			    	   var node = tree.getRootNode().childNodes[i];
			    	   if(node.get("text") == text){
			    		   AjaxUtils.showError("需要创建的表单已经存在");
			    		   return;
			    	   }
			       }
			       var newNode = Ext.create('Ext.data.NodeInterface',{
			    	   leaf:false
			       });
			       var newNode = tree.getRootNode().createNode(newNode);
		           newNode.set("text",text);
		           newNode.set("leaf",false);
			       tree.getRootNode().appendChild(newNode);
			       //设置表单属性
			       var bkfmWorkFlowForm = new BkfmWorkFlowForm();
			       bkfmWorkFlowForm.setWorkFlowCode(bkfmWorkFlowConfig.getWorkFlowCode());
			       bkfmWorkFlowForm.setWorkFlowName(bkfmWorkFlowConfig.getWorkFlowName());
			       bkfmWorkFlowForm.setWorkFlowFormName(newNode.get("text"));
			       if(Designer.getBkfmWorkFlowForms().hasExistsWorkFlowForm(bkfmWorkFlowForm.getWorkFlowFormName)){
			    	   AjaxUtils.showError("需要创建的表单已经存在");
			    	   return;
			       }
			       Designer.getBkfmWorkFlowForms().addBkfmWorkFlowForm(bkfmWorkFlowForm);
			    }
			});
		},
		/**
		 * 打开已经配置的业务表列表
		 */
		openWorkFlowTableWin: function(callbackFn){
			var win = Ext.create('Ext.com.bkfm.window', {
				//id: "workflow_table_win",
				title : "选择业务表",
				autoScroll : true,
				modal : true,
				height : Utils.getHeight()*0.5,
				width : Utils.getWidth()*0.5,
				items: [Ext.create('Ext.com.bkfm.datagrid', {
					//id: "tables_grid",
					objPath : "ROOT/WORKFLOW/LCGL/BLK_WORKFLOW_TABLES",
					border: true,
					showstandardBtn: false,
					paging: false,
					loadAuto: false,
					tbar:[{
						text: '确定',
						iconCls: 'ok',
						handler: function(self){
							var selfGrid = self.ownerCt.ownerCt;
							Ext.callback(callbackFn,this,[selfGrid.getSelectedRecords(),win]);
						}
					}],
					listeners:{
						render: function(selfGrid,opts){
							var tree = Ext.getCmp("workFlowFormTree");
							var node = tree.getSelectNode();
							//获取流程表单名称
							var workflow_form_name = node.get("text");
							//根据表单名称获取当前表单页面已经配置的配置项列表
							var pageItems = Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(workflow_form_name).getWorkFlowFormPageItems().getBkfmWorkFlowFormPageItems();
							
							var allRecords = Designer.getBkfmWorkFlowTables().getWorkFlowTables();
							var records = [];
							//循环遍历业务配置表列表，剔除在当前表单页面已经配置的业务表
							for(i in allRecords){
								var bkfmWorkFlowTable = allRecords[i];
								var isExists = false;
								for(j in pageItems){
									var bkfmWorkFlowFormPageItem = pageItems[j];
									if(bkfmWorkFlowFormPageItem.getTablePath() == bkfmWorkFlowTable.getTablePath()){
										isExists = true;
										break;
									}
								}
								if(!isExists){
									records.push(bkfmWorkFlowTable);
								}
							}
							//打开显示为配置的业务表
							for(i in records){
								var bkfmWorkFlowTable = records[i];
								//添加到角色grid中
								var newRecord = Ext.create(selfGrid.modelField,{});
								//设置记录状态为新增
								newRecord.state = Constants.RECORD_NEW;
								var rowIndex = selfGrid.getStore().getCount();
								selfGrid.getStore().insert(rowIndex,newRecord);
								newRecord.set("WORKFLOW_CODE",bkfmWorkFlowTable.getWorkFlowCode());
								newRecord.set("WORKFLOW_CODE_DISPLAYVALUE",bkfmWorkFlowTable.getWorkFlowName());
								newRecord.set("TABLE_PATH",bkfmWorkFlowTable.getTablePath());
								newRecord.set("TABLE_PATH_DISPLAYVALUE",bkfmWorkFlowTable.getTableName());
								newRecord.set("TABLE_TYPE",bkfmWorkFlowTable.getTableType());
								newRecord.set("TABLE_TYPE_DISPLAYVALUE",bkfmWorkFlowTable.getTableTypeName());
							}
						}
					}
				})]
			}).show();
		},
		/**
		 * 添加表单对应页面配置对象
		 * @param bkfmWorkFlowFormPageItem配置对象
		 * @param isRepaint 是否重绘true：表示点击表单页面重新绘制表单页面配置项，不需要重复存储数据，false：表示为新增表单页面配置项，需要添加存储
		 */
		addWorkFlowPageItem: function(bkfmWorkFlowFormPageItem,isRepaint){
			var portalPanel = Ext.getCmp("formDesignerPanel");
			//根据配置项表路径和表单名称，判断当前配置项在指定的表单页面中是否已经配置存在
			if(bkfmWorkFlowFormPageItem.getPageItemType() == bkfmWorkFlowFormPageItem.PAGEITEM_TYPE_FORM_CODE){
				//表单
				portalPanel.add({
					title: bkfmWorkFlowFormPageItem.getPageTitle(),
					tools:[{
			            xtype: 'tool',
			            type: 'gear',
			            tooltip: '表单设置',
			            tooltipType:'title',
			            handler: function(e, target, header, tool){
			            	WorkFlowForm.createPageItemFieldsPermis(header.ownerCt);
			            }
			        },{
			            xtype: 'tool',
			            type: 'close',
			            tooltip: '关闭',
			            tooltipType:'title',
			            handler: function(e, target, header, tool){
			            	WorkFlowForm.onPortletClose(header.ownerCt);
			            }
			        }],
			        closable: false,
					items:[WorkFlowForm.addWorkFlowPageItemForm(bkfmWorkFlowFormPageItem)],
					listeners:{
						move: function(){
							//配置项移动
							//debugger;
							//重新设置排序位置
            				//Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(bkfmWorkFlowFormPageItem.getWorkFlowFormName()).sortForm();
							WorkFlowForm.sortPortalItem(portalPanel,bkfmWorkFlowFormPageItem.getWorkFlowFormName());
	                	}
					}
				});
				
			}else if(bkfmWorkFlowFormPageItem.getPageItemType() == bkfmWorkFlowFormPageItem.PAGEITEM_TYPE_GRID_CODE){
				//表格
				portalPanel.add({
					title: bkfmWorkFlowFormPageItem.getPageTitle(),
					tools:[{
			            xtype: 'tool',
			            type: 'gear',
			            tooltip: '表格设置',
			            tooltipType:'title',
			            handler: function(e, target, header, tool){
			            	WorkFlowForm.createPageItemFieldsPermis(header.ownerCt);
			            }
			        },{
			            xtype: 'tool',
			            type: 'close',
			            tooltip: '关闭',
			            tooltipType:'title',
			            handler: function(e, target, header, tool){
			            	WorkFlowForm.onPortletClose(header.ownerCt);
			            }
			        }],
			        closable: false,
					items:[WorkFlowForm.addWorkFlowPageItemGrid(bkfmWorkFlowFormPageItem)],
					listeners:{
						move: function(){
							//配置项移动
							//debugger;
							//重新设置排序位置
							WorkFlowForm.sortPortalItem(portalPanel,bkfmWorkFlowFormPageItem.getWorkFlowFormName());
	                	}
					}
				});
				
			}
			if(!isRepaint){
				//非页面重绘需要添加到存储结构中
				Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(bkfmWorkFlowFormPageItem.getWorkFlowFormName()).getWorkFlowFormPageItems().addBkfmWorkFlowFormPageItem(bkfmWorkFlowFormPageItem);
			}
		},
		/**
		 * 重新排序表单页面配置项位置
		 * portalPanel：portal对象
		 * workflow_form_name： 表单名称
		 */
		sortPortalItem: function(portalPanel,workflow_form_name){
			var bkfmWorkFlowFormPageItems = new BkfmWorkFlowFormPageItems();//Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(workflow_form_name).getWorkFlowFormPageItems()
			for(i in portalPanel.items.items){
				var ownerItem = portalPanel.items.items[i];
				var portalItem = ownerItem.items.items[0];
				var bkfmWorkFlowFormPageItem = portalItem.getBkfmWorkFlowFormPageItem();
				bkfmWorkFlowFormPageItem.setOrderBy(i);
				//bkfmWorkFlowFormPageItems.setBkfmWorkFlowFormPageItem(bkfmWorkFlowFormPageItem);
				bkfmWorkFlowFormPageItems.addBkfmWorkFlowFormPageItem(bkfmWorkFlowFormPageItem);
			}
			Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(workflow_form_name).setWorkFlowFormPageItems(bkfmWorkFlowFormPageItems);
		},
		/**
		 * 添加表单页面配置项-表单
		 */
		addWorkFlowPageItemForm: function(bkfmWorkFlowFormPageItem){
			return Ext.create('Ext.com.bkfm.form', {
				showGroup : false,
				columnCount: (bkfmWorkFlowFormPageItem.getPageItemFormColumnCount()>0) ? bkfmWorkFlowFormPageItem.getPageItemFormColumnCount():4,
				border : false,
				frameborder : false,
				objPath : bkfmWorkFlowFormPageItem.getTablePath(),
				saveObjPath: bkfmWorkFlowFormPageItem.getTablePath(),
				height: bkfmWorkFlowFormPageItem.getPageItemHeight(),
				bkfmWorkFlowFormPageItem: bkfmWorkFlowFormPageItem,
				/**
				 * 获取表单页面配置项对象
				 */
				getBkfmWorkFlowFormPageItem: function(){
					return this.bkfmWorkFlowFormPageItem;
				},
				//工具栏
				dockedItems:[{
					xtype: 'toolbar',
					dock:'top',
					hidden: true
				}],
				disabled: true
			});
		},
		/**
		 * 添加表单页面配置项-表格
		 */
		addWorkFlowPageItemGrid: function(bkfmWorkFlowFormPageItem){
			return Ext.create('Ext.com.bkfm.datagrid', {
				objPath : bkfmWorkFlowFormPageItem.getTablePath(),
				border: true,
				showstandardBtn: false,
				loadAuto: false,
				paging: false,
				height: bkfmWorkFlowFormPageItem.getPageItemHeight(),
				bkfmWorkFlowFormPageItem: bkfmWorkFlowFormPageItem,
				/**
				 * 获取表单页面配置项对象
				 */
				getBkfmWorkFlowFormPageItem: function(){
					return this.bkfmWorkFlowFormPageItem;
				},
				//工具栏，默认隐藏
				dockedItems:[{
					xtype: 'toolbar',
					dock:'top',
					hidden: true
				}],
				disabled: true,
				enableColumnHide: false,
				listeners:{
					render: function(grid,opts){
						var tbar = grid.getDockedItems('toolbar[dock="top"]')[0];
						var toolbar = [];
						if(bkfmWorkFlowFormPageItem.getIsAdd() == Constants.YES){
							toolbar.push({
								text: '新增',
								iconCls: 'add'
							});
						}
						if(bkfmWorkFlowFormPageItem.getIsEdit() == Constants.YES){
							toolbar.push({
								text: '编辑',
								iconCls: 'edit'
							});
						}
						if(bkfmWorkFlowFormPageItem.getIsDelete() == Constants.YES){
							toolbar.push({
								text: '删除',
								iconCls: 'delete'
							});
						}
						tbar.add(toolbar);
						tbar.setVisible(true);
					}
				}
			});
		},
		/**
		 * 设置表单页面配置项的字段权限
		 * 分别设置只读字段和隐藏字段
		 */
		createPageItemFieldsPermis: function(portal){
			//获取表单页面对应的配置项
			var bkfmWorkFlowFormPageItem = portal.items.get(0).getBkfmWorkFlowFormPageItem();
			var win = Ext.create('Ext.com.bkfm.window', {
				title : "模块权限",
				autoScroll : true,
				modal : true,
				height : Utils.getHeight()*0.7,
				width : Utils.getWidth()*0.6,
				listeners:{
					show: function(winform){
						if(bkfmWorkFlowFormPageItem.getPageItemType() == bkfmWorkFlowFormPageItem.PAGEITEM_TYPE_GRID_CODE){
							//如果当前配置项为表格，隐藏只读字段配置列表
							var readOnlyPanel = winform.items.items[0].items.items[1];
							winform.items.items[0].child(readOnlyPanel).tab.hide();
						}

					}
				},
				items:[{
					xtype: 'tabpanel',
					items:[{
						title: '模块配置',
						id: "baseConfigPanel",
						layout: 'fit',
						items:[Ext.create('Ext.com.bkfm.form', {
							showGroup : false,
							border : false,
							frameborder : false,
							columnCount: 1,
							objPath : "ROOT/WORKFLOW/LCGL/BLK_WORKFLOW_FORM_PAGECONFIGITEM_ATTR",
							textOnlyField: ['PAGECONFIGITEM_RWID'],
							hiddenField: (bkfmWorkFlowFormPageItem.getPageItemType() == bkfmWorkFlowFormPageItem.PAGEITEM_TYPE_FORM_CODE)?['IS_ADD','IS_EDIT','IS_DELETE']:['IS_SAVE','PAGEITEM_FORM_COLUMNCOUNT'],
							listeners:{
								afterrender: function(form,opts){
									form.findById("PAGECONFIGITEM_RWID").fillValue({
										"VALUE": bkfmWorkFlowFormPageItem.getRwid(),
										"DISPLAYVALUE": bkfmWorkFlowFormPageItem.getTableName()
									});
									//设置保存按钮
									if(bkfmWorkFlowFormPageItem.getIsSave() == Constants.YES){
										form.findById("IS_SAVE").fillValue({
											"VALUE": Constants.YES,
											"DISPLAYVALUE": Constants.YES_ZH
										});
									}else{
										form.findById("IS_SAVE").fillValue({
											"VALUE": Constants.NO,
											"DISPLAYVALUE": Constants.NO_ZH
										});
									}
									//设置新增按钮
									if(bkfmWorkFlowFormPageItem.getIsAdd() == Constants.YES){
										form.findById("IS_ADD").fillValue({
											"VALUE": Constants.YES,
											"DISPLAYVALUE": Constants.YES_ZH
										});
									}else{
										form.findById("IS_ADD").fillValue({
											"VALUE": Constants.NO,
											"DISPLAYVALUE": Constants.NO_ZH
										});
									}
									//设置编辑按钮
									if(bkfmWorkFlowFormPageItem.getIsEdit() == Constants.YES){
										form.findById("IS_EDIT").fillValue({
											"VALUE": Constants.YES,
											"DISPLAYVALUE": Constants.YES_ZH
										});
									}else{
										form.findById("IS_EDIT").fillValue({
											"VALUE": Constants.NO,
											"DISPLAYVALUE": Constants.NO_ZH
										});
									}
									//设置删除按钮
									if(bkfmWorkFlowFormPageItem.getIsDelete() == Constants.YES){
										form.findById("IS_DELETE").fillValue({
											"VALUE": Constants.NO,
											"DISPLAYVALUE": Constants.NO_ZH
										});
									}else{
										form.findById("IS_DELETE").fillValue({
											"VALUE": Constants.NO,
											"DISPLAYVALUE": Constants.NO_ZH
										});
									}
									//设置配置项高度
									form.findById("PAGEITEM_HEIGHT").setValue(parseInt(bkfmWorkFlowFormPageItem.getPageItemHeight()));
									//设置表单配置项每行显示几列
									form.findById("PAGEITEM_FORM_COLUMNCOUNT").setValue(parseInt(bkfmWorkFlowFormPageItem.getPageItemFormColumnCount()));
								}
							}
						})]
					},{
						title: '只读配置',
						id: 'readOnlyFieldsPanel',
						layout: 'fit',
						items:[Ext.create('Ext.com.bkfm.datagrid', {
							objPath : "ROOT/WORKFLOW/LCGL/BLK_WORKFLOW_FORM_PAGECONFIGITEM_PERMIS",
							border: true,
							showstandardBtn: false,
							loadAuto: false,
							paging: false,
							checkBoxOnly: true,
							hiddenField: ['PAGECONFIGITEM_RWID','READONLY_FIELDS','HIDDEN_FIELDS'],
							userConfigColumn:[{
								name: 'FIELD_ID',
								text: '字段',
								dataIndex: 'FIELD_ID',
								renderer: function(value, cellmeta, record, rowIndex, columnIndex, store){
									return record.FIELD_ID;
								}
							},{
								name: 'FIELD_NAME',
								text: '字段名称',
								dataIndex: 'FIELD_NAME',
								renderer: function(value, cellmeta, record, rowIndex, columnIndex, store){
									return record.FIELD_NAME;
								}
							}],
							listeners:{
								render: function(selfGrid,opts){
									//获取配置项对象的只读字段列表
									var bkfmWorkFlowFormPageItemReadOnlyFields = bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemReadOnlyFields();
									//存储已经设置的字段列表
									var hasConfigFields=[];
									for(i in bkfmWorkFlowFormPageItemReadOnlyFields.getBkfmWorkFlowFormPageItemReadOnlyFields()){
										var bkfmWorkFlowFormPageItemReadOnlyField = bkfmWorkFlowFormPageItemReadOnlyFields.getBkfmWorkFlowFormPageItemReadOnlyFields()[i]
										hasConfigFields.push(bkfmWorkFlowFormPageItemReadOnlyField.getFieldId());
									}
									BkfmDBUtils.Query("SELECT ZH_CN,EN_US FROM BLK_TABLE_METADATA WHERE FATHER_TABLEMETADATA_ID IN (SELECT TABLEMETADATA_ID FROM BLK_TABLE_METADATA WHERE OBJ_PATH='"+bkfmWorkFlowFormPageItem.getTablePath()+"')  ORDER BY ORDER_BY ASC",function(result){
										//需要选中行的索引
										var selectIndex = [];
										for(i in result.list){
											var record = result.list[i];
											var bkfmWorkFlowFormPageItemReadOnlyField = new BkfmWorkFlowFormPageItemReadOnlyField();
											bkfmWorkFlowFormPageItemReadOnlyField.setFieldId(record.EN_US);
											bkfmWorkFlowFormPageItemReadOnlyField.setFieldName(record.ZH_CN);
											
											var newRecord = Ext.create(selfGrid.modelField,{});
											//设置记录状态为新增
											newRecord.state = Constants.RECORD_NEW;
											newRecord.FIELD_ID = bkfmWorkFlowFormPageItemReadOnlyField.getFieldId();
											newRecord.FIELD_NAME = bkfmWorkFlowFormPageItemReadOnlyField.getFieldName();
											var rowIndex = selfGrid.getStore().getCount();
											selfGrid.getStore().insert(rowIndex,newRecord);
											
											//判断当前行是否需要选中
											if(Ext.Array.contains(hasConfigFields,bkfmWorkFlowFormPageItemReadOnlyField.getFieldId())){
												//设置需要选中的行索引
												selectIndex.push(i);
											}
										}
										
										for(k in selectIndex){
											var index = selectIndex[k];
											selfGrid.selectRecordByIndex(parseInt(index));
										}
									});
								}
							}
						})]
					},{
						title: '隐藏配置',
						layout: 'fit',
						id: 'hiddenFieldsPanel',
						items:[Ext.create('Ext.com.bkfm.datagrid', {
							objPath : "ROOT/WORKFLOW/LCGL/BLK_WORKFLOW_FORM_PAGECONFIGITEM_PERMIS",
							border: true,
							showstandardBtn: false,
							loadAuto: false,
							paging: false,
							checkBoxOnly: true,
							hiddenField: ['PAGECONFIGITEM_RWID','READONLY_FIELDS','HIDDEN_FIELDS'],
							userConfigColumn:[{
								name: 'FIELD_ID',
								text: '字段',
								dataIndex: 'FIELD_ID',
								renderer: function(value, cellmeta, record, rowIndex, columnIndex, store){
									return record.FIELD_ID;
								}
							},{
								name: 'FIELD_NAME',
								text: '字段名称',
								dataIndex: 'FIELD_NAME',
								renderer: function(value, cellmeta, record, rowIndex, columnIndex, store){
									return record.FIELD_NAME;
								}
							}],
							listeners:{
								render: function(selfGrid,opts){
									//获取配置项对象的只读字段列表
									var bkfmWorkFlowFormPageItemHiddenFields = bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemHiddenFields();
									//存储已经设置的字段列表
									var hasConfigFields=[];
									for(i in bkfmWorkFlowFormPageItemHiddenFields.getBkfmWorkFlowFormPageItemHiddenFields()){
										var bkfmWorkFlowFormPageItemHiddenField = bkfmWorkFlowFormPageItemHiddenFields.getBkfmWorkFlowFormPageItemHiddenFields()[i]
										hasConfigFields.push(bkfmWorkFlowFormPageItemHiddenField.getFieldId());
									}
									BkfmDBUtils.Query("SELECT ZH_CN,EN_US FROM BLK_TABLE_METADATA WHERE FATHER_TABLEMETADATA_ID IN (SELECT TABLEMETADATA_ID FROM BLK_TABLE_METADATA WHERE OBJ_PATH='"+bkfmWorkFlowFormPageItem.getTablePath()+"')  ORDER BY ORDER_BY ASC",function(result){
										//需要选中行的索引
										var selectIndex = [];
										for(i in result.list){
											var record = result.list[i];
											var bkfmWorkFlowFormPageItemHiddenField = new BkfmWorkFlowFormPageItemHiddenField();
											bkfmWorkFlowFormPageItemHiddenField.setFieldId(record.EN_US);
											bkfmWorkFlowFormPageItemHiddenField.setFieldName(record.ZH_CN);
											
											var newRecord = Ext.create(selfGrid.modelField,{});
											//设置记录状态为新增
											newRecord.state = Constants.RECORD_NEW;
											newRecord.FIELD_ID = bkfmWorkFlowFormPageItemHiddenField.getFieldId();
											newRecord.FIELD_NAME = bkfmWorkFlowFormPageItemHiddenField.getFieldName();
											var rowIndex = selfGrid.getStore().getCount();
											selfGrid.getStore().insert(rowIndex,newRecord);
											
											//判断当前行是否需要选中
											if(Ext.Array.contains(hasConfigFields,bkfmWorkFlowFormPageItemHiddenField.getFieldId())){
												//设置需要选中的行索引
												selectIndex.push(i);
											}
										}
										//选中
										for(k in selectIndex){
											var index = selectIndex[k];
											selfGrid.selectRecordByIndex(parseInt(index));
										}
									});
								}
							}
						})]
					}]
				}],
				buttons:[{
					text: '保存',
					iconCls: 'save',
					handler: function(){
						//保存模板配置信息
						var baseConfigForm = Ext.getCmp("baseConfigPanel").items.get(0);
						bkfmWorkFlowFormPageItem.setIsSave(baseConfigForm.findById("IS_SAVE").getValue());
						bkfmWorkFlowFormPageItem.setIsAdd(baseConfigForm.findById("IS_ADD").getValue());
						bkfmWorkFlowFormPageItem.setIsEdit(baseConfigForm.findById("IS_EDIT").getValue());
						bkfmWorkFlowFormPageItem.setIsDelete(baseConfigForm.findById("IS_DELETE").getValue());
						bkfmWorkFlowFormPageItem.setPageItemHeight(baseConfigForm.findById("PAGEITEM_HEIGHT").getValue());
						bkfmWorkFlowFormPageItem.setPageItemFormColumnCount(baseConfigForm.findById("PAGEITEM_FORM_COLUMNCOUNT").getValue());
						
						//保存只读字段，获取选配的只读字段
						var readOnlyFields = Ext.getCmp("readOnlyFieldsPanel").items.get(0).getSelectedRecords();
						//删除所有只读字段
						bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemReadOnlyFields().removeAll();
						//重新添加设置的只读字段
						for(i in readOnlyFields){
							var record = readOnlyFields[i];
							var bkfmWorkFlowFormPageItemReadOnlyField = new BkfmWorkFlowFormPageItemReadOnlyField();
							bkfmWorkFlowFormPageItemReadOnlyField.setFieldId(record.FIELD_ID);
							bkfmWorkFlowFormPageItemReadOnlyField.setFieldName(record.FIELD_NAME);
							//重新添加
							bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemReadOnlyFields().addBkfmWorkFlowFormPageItemReadOnlyField(bkfmWorkFlowFormPageItemReadOnlyField);
						}
						
						//保存隐藏字段
						var hiddenFields = Ext.getCmp("hiddenFieldsPanel").items.get(0).getSelectedRecords();
						//删除所有隐藏字段
						bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemHiddenFields().removeAll();
						//重新添加设置的隐藏字段
						for(i in hiddenFields){
							var record = hiddenFields[i];
							var bkfmWorkFlowFormPageItemHiddenField = new BkfmWorkFlowFormPageItemHiddenField();
							bkfmWorkFlowFormPageItemHiddenField.setFieldId(record.FIELD_ID);
							bkfmWorkFlowFormPageItemHiddenField.setFieldName(record.FIELD_NAME);
							//重新添加
							bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemHiddenFields().addBkfmWorkFlowFormPageItemHiddenField(bkfmWorkFlowFormPageItemHiddenField);
						}
						
						AjaxUtils.showInfo("保存成功",function(){
							win.close();
						});
					}
				},{
					text: '关闭',
					iconCls: 'close',
					handler: function(){
						win.close();
					}
				}]
			});
			win.show();
		},
		/**
		 * 打开指定表单页面所有的页面配置项,
		 * workflow_form_name 表单页面名称
		 * is_view: 是否预览true，false
		 */
		viewWorkFlowPageItems: function(workflow_form_name){
			//根据表单名称获取当前表单页面已经配置的配置项列表
			var pageItems = Designer.getBkfmWorkFlowForms().getBkfmWorkFlowForm(workflow_form_name).getWorkFlowFormPageItems().getBkfmWorkFlowFormPageItems();
			var viewPageItems = [];
			for(i in pageItems){
				var bkfmWorkFlowFormPageItem = pageItems[i];
				//获取只读字段
				var readOnlyFields = [];
				for(i in bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemReadOnlyFields().getBkfmWorkFlowFormPageItemReadOnlyFields()){
					var bkfmWorkFlowFormPageItemReadOnlyField = bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemReadOnlyFields().getBkfmWorkFlowFormPageItemReadOnlyFields()[i];
					readOnlyFields.push(bkfmWorkFlowFormPageItemReadOnlyField.getFieldId());
				}
				//获取隐藏字段
				var hiddenFields = [];
				for(i in bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemHiddenFields().getBkfmWorkFlowFormPageItemHiddenFields()){
					var bkfmWorkFlowFormPageItemHiddenField = bkfmWorkFlowFormPageItem.getBkfmWorkFlowFormPageItemHiddenFields().getBkfmWorkFlowFormPageItemHiddenFields()[i];
					hiddenFields.push(bkfmWorkFlowFormPageItemHiddenField.getFieldId());
				}
				var item = null;
				if(bkfmWorkFlowFormPageItem.getPageItemType() == bkfmWorkFlowFormPageItem.PAGEITEM_TYPE_FORM_CODE){
					item = top.Ext.create('Ext.com.bkfm.form', {
						title: bkfmWorkFlowFormPageItem.getTableName(),
						showGroup : false,
						columnCount: (bkfmWorkFlowFormPageItem.getPageItemFormColumnCount()>0) ? bkfmWorkFlowFormPageItem.getPageItemFormColumnCount():4,
						border : false,
						frameborder : false,
						objPath : bkfmWorkFlowFormPageItem.getTablePath(),
						saveObjPath: bkfmWorkFlowFormPageItem.getTablePath(),
						height: bkfmWorkFlowFormPageItem.getPageItemHeight(),
						textOnlyField: readOnlyFields,
						hiddenField: hiddenFields
					});
				}else if(bkfmWorkFlowFormPageItem.getPageItemType() == bkfmWorkFlowFormPageItem.PAGEITEM_TYPE_GRID_CODE){
					item = top.Ext.create('Ext.com.bkfm.datagrid', {
						title: bkfmWorkFlowFormPageItem.getTableName(),
						objPath : bkfmWorkFlowFormPageItem.getTablePath(),
						border: true,
						showstandardBtn: false,
						loadAuto: false,
						paging: false,
						height: bkfmWorkFlowFormPageItem.getPageItemHeight(),
						hiddenField: hiddenFields,
						enableColumnHide: false,
						dockedItems:[{
							xtype: 'toolbar',
							dock:'top',
							hidden: true
						}],
						listeners:{
							render: function(grid,opts){
								var tbar = grid.getDockedItems('toolbar[dock="top"]')[0];
								var toolbar = [];
								if(bkfmWorkFlowFormPageItem.getIsAdd() == Constants.YES){
									toolbar.push({
										text: '新增',
										iconCls: 'add'
									});
								}
								if(bkfmWorkFlowFormPageItem.getIsEdit() == Constants.YES){
									toolbar.push({
										text: '编辑',
										iconCls: 'edit'
									});
								}
								if(bkfmWorkFlowFormPageItem.getIsDelete() == Constants.YES){
									toolbar.push({
										text: '删除',
										iconCls: 'delete'
									});
								}
								tbar.add(toolbar);
								tbar.setVisible(true);
							}
						}
					});
				}
				if(item !=null){
					viewPageItems.push(item);
				}
			}
			
			top.Ext.create('Ext.com.bkfm.window', {
				title : "表单【"+workflow_form_name+"】-预览",
				autoScroll : true,
				modal : true,
				height : top.Utils.getHeight()*0.8,
				width : top.Utils.getWidth()*0.9,
				items:[{
					xtype: 'panel',
					id: "view_container",
					autoScroll : true,
					style: 'padding:10px',
					items: viewPageItems
				}]
			}).show();
		}
}

